1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #5338

    +159

    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
    <?
    mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
    mysql_selectdb($db) or die(mysql_error());
    $q = "SELECT `login`, `email`, `name`, `second_name`, `age` FROM $db.accounts WHERE login='".$_SESSION['login']."' ";
    $res = mysql_query($q) or die(mysql_error());
    $row=mysql_fetch_array($res);?>
    ...
    <?
    $name = $_POST['name'];
    $email = $_POST['email'];
    $log = $_SESSION['name'];
    $second_name = $_POST['second_name'];
    $age = $_POST['age'];
    mysql_connect("$db_host", "$db_user", "$db_pass") or die(mysql_error());
    mysql_selectdb($db) or die(mysql_error());
    $query = "UPDATE accounts SET name ='$name', second_name='$second_name', email='$email', age='$age' WHERE login = '$log'";
    mysql_query($query) or die(mysql_error());
    ?>

    http://www.php.ru/forum/viewtopic.php?t=30226
    Туча ошибок и проблемы с безопасностью

    Devzirom, 20 Января 2011

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if ('$kaax' in window)
    	if ($kaax === undefined) $kaax = {defval : $kaax}; else
    	if ($kaax === null) $kaax = {defval : null}; else
    	$kaax.defval = $kaax;
    else
    	var $kaax = {};
    
    ...
    
    $kaax = $kaax.defval;

    Параноик объявляет переменную.
    Тот факт, что window/undefined могут быть переопределены либо $kaax уже иметь свойство defval, упускается.

    fuckyounoob, 18 Января 2011

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

    +163

    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
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    function load_file( $name, $include_file = "tpl" ) {
    		global $db, $is_logged, $member_id, $cat_info, $config, $user_group, $category_id, $_TIME, $lang, $smartphone_detected, $dle_module;
    
    		$name = str_replace( '..', '', $name );
    
    		$url = @parse_url ($name);
    		$type = explode( ".", $url['path'] );
    		$type = strtolower( end( $type ) );
    
    		if ($type == "tpl") {
    
    			return $this->sub_load_template( $name );
    
    		}
    
    		if ($include_file == "php") {
    
    			if ( !$this->allow_php_include ) return;
    
    			if ($type != "php") return "Для подключения допускаются только файлы с расширением .tpl или .php";
    
    			if ($url['path']{0} == "/" )
    				$file_path = dirname (ROOT_DIR.$url['path']);
    			else
    				$file_path = dirname (ROOT_DIR."/".$url['path']);
    
    			$file_name = pathinfo($url['path']);
    			$file_name = $file_name['basename'];
    
    			if ( stristr ( php_uname( "s" ) , "windows" ) === false )
    				$chmod_value = @decoct(@fileperms($file_path)) % 1000;
    
    			if ( stristr ( dirname ($url['path']) , "uploads" ) !== false )
    				return "Файл находится в недопустимой папке /uploads/";
    
    			if ( stristr ( dirname ($url['path']) , "templates" ) !== false )
    				return "Файл находится в недопустимой папке /templates/";
    
    			if ($chmod_value == 777 ) return "Файл {$url['path']} находится в папке, которая доступна для записи (CHMOD 777). В целях безопасности подключение файлов из таких папок невозможно. Измените права на папку, чтобы на нее небыло прав на запись.";
    
    			if ( !file_exists($file_path."/".$file_name) ) return "Файл {$url['path']} не найден, его загрузка невозможна.";
    
    			if ( $url['query'] ) {
    
    				parse_str( $url['query'] );
    
    			}
    
    			ob_start();
    			$tpl = new dle_template( );
    			$tpl->dir = TEMPLATE_DIR;
    			include $file_path."/".$file_name;
    			return ob_get_clean();
    
    		}
    
    		return '{include file="'.$name.'"}';
    
    
    	}

    DLE software, доставило
    Шеф заказал сайт на этой цмс...

    DanxilLs, 15 Января 2011

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

    +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
    // create singelton object, see below 
    function singelton(classDesc) {
        return classDesc;
    }
    
    
    var LetterTypeAction = singelton(
        {
            selectLetterType : function(controlId, index) {
               letterTypeManager.selectLetterType(controlId, index);
            },
    
            addLetterType : function() {
                letterTypeManager.addLetterType();
            },
    
            saveLetterType : function() {
                var tempLetterType = new LetterTypeDef();
                tempLetterType.setId(currentLetterType.getId());
                tempLetterType.setAbbreviation(TextUtils.trim(ControlUtils.getValueById(letterTypeAbbrId)));
                tempLetterType.setDescription(TextUtils.trim(ControlUtils.getValueById(letterTypeDescrId)));            
    
                letterTypeManager.saveLetterType(tempLetterType);
            },
    
            changeLetterType : function() {
                letterTypeManager.changeLetterType();            
            },
    
            deleteLetterType : function() {
                letterTypeManager.deleteLetterType(currentLetterType);
            },
    
            cancelLetterType : function() {
                letterTypeManager.cancelLetterType();
            },
    
            sortLetterType : function(columnId) {
                letterTypeManager.sortLetterType(columnId);            
            }
        }
    );

    новый паттерн проектирования, добавляющий в код мусор

    tr00_gr1m_doomster, 10 Января 2011

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

    +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
    <?php
    class pvalidator extends validator {	
    	public function fname($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё]{3,16}$/iu", $value);
    	}
    	
    	public function lname($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё]{3,16}$/iu", $value);
    	}
    	
    	public function tname($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё]{3,16}$/iu", $value);
    	}
    	
    	public function nickname($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё \-]{3,32}$/iu", $value);
    	}
    	
    	public function country($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё \-]{2,32}$/iu", $value);
    	}
    	
    	public function sity($value) {
    		return (bool) preg_match("/^[А-Яа-яЁё \-]{2,16}$/iu", $value);
    	}
    	
    	public function school($value) {
    		return (bool) preg_match("/^[№А-Яа-яЁё 0-9\-]{2,16}$/iu", $value);
    	}
    	
    	public function hresponse($value) {
    		return (bool) preg_match("/^.{0,32}$/iu", $value);
    	}
    	
    	public function activity($value) {
    		return (bool) preg_match("/^.{0,32}$/iu", $value);
    	}
    	
    	public function interest($value) {
    		return (bool) preg_match("/^.{0,32}$/iu", $value);
    	}
    }
    ?>

    Моё свежее, с утра высранное!

    Devzirom, 10 Января 2011

    Комментарии (7)
  7. 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)
  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 / Говнокод #5170

    +162

    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
    <?
    // blah blah blah ...
    
    static public function parseCleanValue( $val, $postParse=true )
    {
        if ( $val == "" )
        {
        	return "";
        }
    
        // blah blah blah ...
    }
    
    // blah blah blah ...
    
    ?>

    IP.Board 3.0.4

    /admin/sources/base/core.php:4139

    IPB, такой IPB

    miraage, 06 Января 2011

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

    +145

    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
    <?php 
    if (isset($_GET['offset'])) { 
        $minutes = $_GET['offset']; 
        echo "GMT offset (in minutes, from the browser): ". $minutes ."<br />\n"; 
        echo "GMT: ". gmdate("Y-m-d H:i:s") ."<br />\n"; 
         
        $local = gmmktime(gmdate("H"),gmdate("i")-$minutes); // adjust GMT by client's offset 
         
        echo "Calculated client's date/time: ". gmdate("Y-m-d h:i:s a",$local) ."<br />\n"; 
    } else { 
        echo "<script language='javascript'>\n"; 
        echo "var d = new Date();\n"; 
        echo "location.href=\"${_SERVER['SCRIPT_NAME']}?offset=\" + d.getTimezoneOffset();\n"; 
        echo "</script>\n"; 
        exit(); 
    } 
    ?>

    где здесь пхп, кажется, понятно )

    Lure Of Chaos, 30 Декабря 2010

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

    +173

    1. 1
    $dateEnd = date("Y-m-d",mktime(23, 59, 59, date("m"), date("d"), date("Y")));

    У кого-то хватило ума почитать документацию, а вот понять её - нет.

    trinkl, 27 Декабря 2010

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