1. PHP / Говнокод #5187

    +165

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    $query = mysql_query("SELECT * FROM `accounts` WHERE `login` = '".@$_COOKIE['sc2tACC']."' LIMIT 1");
    if ($query and @isset($_COOKIE['sc2tACC']) AND mysql_num_rows($query)) {
    	$auth = mysql_fetch_array($query);
    	if($auth['password'] == $_COOKIE['sc2tPASS'] and @isset($_COOKIE['sc2tPASS'])) {
    		$AS = "OK";
    		if($_SERVER['PHP_SELF'] != "/chat.php" and $auth['status'] != 1) {
    			mysql_query("UPDATE `accounts` SET `timestamp` = '".microtime(1)."', `ip` = '".$_SERVER['REMOTE_ADDR']."', `lastpage` = '".$_SERVER['REQUEST_URI']."'  WHERE `id` = '".$auth['id']."' LIMIT 1;");
    		}
    	} else {
    		$loginError = "Неверный пароль";
    	}
    } else {
    	$loginError = "Неверный логин";
    }

    ne0n, 09 Января 2011

    Комментарии (4)
  2. Си / Говнокод #5186

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    int function(void) {
        static int i, state = 0;
        switch (state) {
            case 0: /* start of function */
            for (i = 0; i < 10; i++) {
                state = 1; /* so we will come back to "case 1" */
                return i;
                case 1:; /* resume control straight after the return */
            }
        }
    }

    Нестандартное применение свитча.
    Тут оно нафиг не нужно.
    Источник: http://www.gamedev.ru/code/forum/?id=142536

    TarasB, 09 Января 2011

    Комментарии (83)
  3. JavaScript / Говнокод #5185

    +166

    1. 1
    2. 2
    3. 3
    function isArray(o) {
      return Object.prototype.toString.call(o) === '[object Array]';
    }

    ЖИСТОКЕ

    bugmenot, 08 Января 2011

    Комментарии (13)
  4. PHP / Говнокод #5184

    +164

    1. 1
    2. 2
    3. 3
    function isUTF8 ($str) {
        return $utf8 = (preg_match("/^([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/", $str)) ? true : false;
    }

    говно или нет?

    stasoft, 08 Января 2011

    Комментарии (7)
  5. PHP / Говнокод #5183

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    <?php
    
    $res=mysql_query('SELECT hosts FROM site_stats LIMIT 200');
    
    while($row = mysql_fetch_row($res)) {
    $a = array (
    $row[0]
    );
    }
    
    foreach ($a as $v) {
    print "$v. ";
    }
    ?>

    http://www.php.ru/forum/viewtopic.php?t=29941 (если не удалят)

    Devzirom, 08 Января 2011

    Комментарии (8)
  6. PHP / Говнокод #5182

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    <?php
    class VIEW_View
    {
    	private $_path;
    	private $_template;
    	private $_var = array();
    
    	public function __construct($path = '')
    	{
    		$this->_path = $_SERVER['DOCUMENT_ROOT'] . $path;
    	}
    
    	public function set($name, $value)
    	{
    		$this->_var[$name] = $value;
    	}
    
    	public function __get($name)
    	{
    		if (isset($this->_var[$name])) return $this->_var[$name];
    		return '';
    	}
    
    	public function display($template, $strip = true)
    	{
    		$this->_template = $this->_path . $template;
    		if (!file_exists($this->_template)) die('Шаблона ' . $this->_template . ' не существует!');
    
    		ob_start();
    		include($this->_template);
    		echo ($strip) ? $this->_strip(ob_get_clean()) : ob_get_clean();
    	}
    
    	private function _strip($data)
    	{
    		$lit = array("\\t", "\\n", "\\n\\r", "\\r\\n", "  ");
    		$sp = array('', '', '', '', '');
    		return str_replace($lit, $sp, $data);
    	}
    
    	public function xss($data)
    	{
    		if (is_array($data)) {
    			$escaped = array();
    			foreach ($data as $key => $value) {
    				$escaped[$key] = $this->xss($value);
    			}
    			return $escaped;
    		}
    		return htmlspecialchars($data, ENT_QUOTES);
    	}
    }
    ?>

    Тема: "foreach в шаблонизаторе." http://www.php.ru/forum/viewtopic.php?t=29937

    Заголовок в блоге: "Меня зовут — Анатолий Ларин - Архив блога - Прощай Smarty или простой шаблонизатор"
    http://larin.in/archives/16

    Devzirom, 08 Января 2011

    Комментарии (12)
  7. PHP / Говнокод #5181

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    class my_anekdots
    {
        private $url="http://anekdots.ru/roulette.pl?catid=";
        private $type=2;
        private $output;
        private $content;
        public function getRandAnekdots()
        {
            $this->content = file_get_contents($this->url.$this->type);
            $this->parseAnekdots()->_display();
            
        }
        private function parseAnekdots()
        {
            preg_match('|<font face=Tahoma size=2 style="font-size: 11px;"><p align=justify>(.*?)</p></font>|is',$this->content,$matches);
            $this->output = $matches[1];
            $this->output = str_replace('\n','<br />',$this->output);
            return $this;
            
        }
        public function _display()
        {
            echo "<span style='padding:5px;'>".$this->output."</span>";
        }
    }
    $my_anekdots = new my_anekdots;
    $my_anekdots->getRandAnekdots();

    O_op

    DanxilLs, 08 Января 2011

    Комментарии (5)
  8. Ruby / Говнокод #5180

    −100

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    N = 5
    $mas = (1..N).to_a
    $c = 0
     
    def generate(l = 0)
        if l == N-1
            for i in 0..N-1 do
                print("#{$mas[i]} ")
            end
            $c += 1; print("\n")
        else
            for i in l..N-1 do
                t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
                generate(l+1)
                t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
            end
        end
        return $c
    end
     
    p generate(0);

    qbasic, 08 Января 2011

    Комментарии (7)
  9. PHP / Говнокод #5179

    +34

    1. 1
    2. 2
    foreach($keys as $key) 
         $settings[$type][$fieldname][$key] =  (isset($fl[$type] [$fieldname] ['widget'] [$key] ) ) ? $fl[$type] [$fieldname] ['widget'] [$key] : '';

    вобля

    brainstorm, 08 Января 2011

    Комментарии (10)
  10. PHP / Говнокод #5178

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    <?php 
     error_reporting(E_ALL | E_STRICT); 
     ini_set("display_errors", "1"); 
      
     setlocale(LC_ALL, 'ru_RU.CP1251', 'rus_RUS.CP1251', 'Russian_Russia.1251'); 
     
      
     $text='[email protected] , [email protected]';
    
     
     $poisk='/([^,]+@.+?\.(?:com|ru|de|en))/si';
     
     
     preg_match_all($poisk,$text,$match);
     
     foreach ($match[1] as $value)
    
    {
    echo $value;
    echo '<br>';
     
    }
     
     
      
     ?>

    Тема: Регулярка для почты.

    http://www.php.ru/forum/viewtopic.php?p=256681#256681

    Devzirom, 07 Января 2011

    Комментарии (15)