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

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

    +160

    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
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    <?php
    //error_reporting(0);
    list($sms, $ss) = explode(' ', microtime());
    $start_time=($ss+$sms);
    unset($sms);
    unset($ss);
    include ROOT.'config.php';
    define('VERSION', '0.8');
    if(!isset($installed) && $_SERVER['PHP_SELF']!='/install.php') header("Location: /install.php");
    if(isset($installed)) $db = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect to database server');
    if(isset($installed))mysql_select_db($dbname) or die('Could not select database');
    if(isset($installed)) mysql_set_charset('utf8');
    $sql_query_cnt = 1;
    
    function db_fetch_obj_all($query){
      $res = mysql_query($query);
      $GLOBALS['sql_query_cnt']++;
      if($res==false) retnulla($query);
      $foa = array();
      while($fo = @mysql_fetch_object($res)) $foa[]=$fo;
      return $foa;
    }
    
    function db_query($q){
      $res = mysql_query($q);
      $GLOBALS['sql_query_cnt']++;
      if($res==false) retnulla($q);
      return $res;
    }
    
    function retnulla($q){
      echo '<div class="warn">Ошибка при выполнении SQL-запроса</div><div class="post">'.$q.'</div><div class="post">'.mysql_error().'</div>';
    }
    
    function getConf($key){
      $cfg = db_fetch_obj_all("SELECT * FROM `tcms_config` WHERE `name`='$key'");
      return $cfg[0]->value;
    }
    
    function at_page(){
      global $loggedin;
      if($loggedin){
        $fobj = db_fetch_obj_all('SELECT * FROM `tcms_users` WHERE `id`='.$_SESSION['uid']);
        return $fobj[0]->at_page;
      }
      else return getConf('at_page');
    }
    
    function curr_theme(){
      global $loggedin;
      if($loggedin){
        $fobj = db_fetch_obj_all('SELECT * FROM `tcms_users` WHERE `id`='.$_SESSION['uid']);
        return $fobj[0]->use_theme;
      }
      else return getConf('default_theme');
    }
    
    function puthead($title=''){
    global $uid;
    if($title!='') $page_name = $title;
    include ROOT.'themes/'.curr_theme().'/head.php';
    }
    function putfoot($menu=''){
    global $foot_menu, $mode;
    if($menu!='') $foot_menu.= ' | '.$menu;
    include ROOT.'themes/'.curr_theme().'/foot.php';
    }
    
    session_start();
    $loggedin = false;
    if(isset($_SESSION['uid'])) $loggedin = true;
    if($loggedin){
      $fobj = db_fetch_obj_all('SELECT * FROM `tcms_users` WHERE `id`='.$_SESSION['uid']);
      $uid = $fobj[0]->id;
      $login = $fobj[0]->login;
      $mode = $fobj[0]->mode;
      $ban = $fobj[0]->ban;
      $banned = $ban>time();
      if($banned) $tobanend = $ban-time();
    }else $mode=0;
    
    function escape($str){
    $str = htmlspecialchars($str);
    $str = mysql_real_escape_string($str);
    return $str;
    }
    
    function lower($str){
      return mb_strtolower($str, 'utf8');
    }
    
    function len($str){
      return mb_strlen($str, 'utf8');
    }
    
    // и так далее...

    func.php
    А ООП в class.php там просто отпад.
    Там всю систему сюда постить надо, лол.
    Сношу архив нафиг, такой код нужно сжигать в доменных печах.

    7ion, 23 Января 2011

    Комментарии (7)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)