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

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

    +156

    1. 1
    2. 2
    $postid = htmlspecialchars($_POST['postid']);
    mysql_query("UPDATE posts SET comments = comments + 1 WHERE id = $postid");

    Кусок из Light CMS :)

    invision70, 06 Июля 2011

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

    +156

    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
    <?php 
    	if(isset($_GET["status"])) {
    		//Определяем переменные
    		$user_id = $_GET['user_id'];
    		$operator_id = $_GET['operator_id'];
    		$smsid = $_GET['smsid'];
    		$operator_id_str = $_GET['operator_id_str'];
    		$num = $_GET['num'];
    		$msg_trans = $_GET['msg_trans'];
    		$msg = $_GET['msg'];
    		$cost_rur = $_GET['cost_rur'];
    		$ratepoints = $cost_rur; //Рейтинг = стоимость смс
    		
    		//Подключаемся к бд
    		$dblocation = "localhost";	 // Имя сервера
    		$dbuser = "****";          // Имя пользователя
    		$dbpasswd = "******";            // Пароль
    		$dbname = "******"; //Имя бд
    		$dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);
    		if (!$dbcnx) {
    			  echo("Не удалось установить соеденение");
    			  exit();
    		} else  {
    						if (!@mysql_select_db($dbname, $dbcnx)) {
    							  echo  "База данных недоступна <br />" ;
    							  exit();
    						} else {
    							//Проверяем зарегестрирован ли пользователь
    							$changeuser = @mysql_query("SELECT * FROM jos_users WHERE  username='$user_id'");
    							if(@mysql_num_rows($changeuser) > 0) {
    							//Пользователь зарегестрирован
    								@mysql_query("INSERT INTO sms (operator_id, operator_id_str, user_id, smsid, num, msg_trans, msg, cost_rur) VALUES ('$operator_id','$operator_id_str','$user_id','$smsid','$num','$msg_trans','$msg','$cost_rur')"); //Добавляем смс
    								@mysql_query("UPDATE jos_users SET rate = rate +1 WHERE username='$user_id'"); //Увеличиваем рейтинг
    								@mysql_query("UPDATE jos_users SET sms = sms +1 WHERE username='$user_id'"); //Увеличиваем кол-во смс
    								$rate = @mysql_fetch_array(@mysql_query("SELECT rate FROM jos_users WHERE username='$user_id'"));
    								echo "SMS Send OK rate +1 your rate: ".$rate['rate']."";
    							} else {
    							/*Пользователь не зарегестрирован,
    							Регестрируем пользователя*/
    							$regdate = date("Y-m-d  H:i:s");
    							
    							//Генерируем пароль
    							$pass = rand(10000, 99999);
    							$sqlpass = md5($pass);
    							
    							//Добавляем пользователя
    								@mysql_query("INSERT INTO jos_users (name, username, password, usertype, gid, registerDate, lastvisitDate) VALUES ('$user_id', '$user_id', '$sqlpass', 'Registered', '18', '$regdate', '$regdate')");
    								$getnewuserid = @mysql_fetch_array(@mysql_query("SELECT id FROM jos_users WHERE username='$user_id'"));
    								@mysql_query("INSERT INTO jos_core_acl_aro (section_value, value, order_value, name, hidden) VALUES ('users', '{$getnewuserid['id']}', '0', '$user_id', '0')");
    								$getaro_id = @mysql_fetch_array(@mysql_query("SELECT id FROM jos_core_acl_aro WHERE name='$user_id'"));
    								@mysql_query("INSERT INTO jos_core_acl_groups_aro_map (group_id, aro_id) VALUES ('18', '{$getaro_id['id']}')");
    								
    								@mysql_query("INSERT INTO sms (operator_id, operator_id_str, user_id, smsid, num, msg_trans, msg, cost_rur) VALUES ('$operator_id','$operator_id_str','$user_id','$smsid','$num','$msg_trans','$msg','$cost_rur')"); 
    								@mysql_query("UPDATE jos_users SET rate = rate +1 WHERE username='$user_id'");
    								@mysql_query("UPDATE jos_users SET sms = sms +1 WHERE username='$user_id'");
    								$rate = @mysql_fetch_array(@mysql_query("SELECT rate FROM jos_users WHERE username='$user_id'"));
    								echo "SMS Register complete. Login: ".$user_id." Pass: ".$pass." Your rate: ".$rate['rate']."";
    							}
    									}
    			}
    	}
    ?>

    phplamer, 20 Июня 2011

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

    +156

    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
    class sqlinj
    {
    ...
    public $liste=array("=","\'","\"","*","\-","declare","char","set","cast","convert","drop","exec","meta","script","select","truncate","insert","delete","union","update","create","where","join","information_schema","table_schema","into");
    ...
    private function tumsorgular($yapilacak){ 
                switch ($yapilacak){ 
                case "post": 
                $this->islet=array("POST"); 
                break; 
                case "get": 
                $this->islet=array("GET"); 
                break; 
                case "request": 
                $this->islet=array("REQUEST"); 
                break; 
                case "aio": 
                $this->islet=array("POST","GET","REQUEST"); 
                break; 
            }     
            foreach($this->islet as $islem){ 
            eval('foreach($_'.$islem.' as $ad=>$deger){ 
                $_'.$islem.'[$ad]=$deger; 
                foreach($this->liste as $bul){ 
                $_'.$islem.'[$ad]=str_replace($bul,"\\\".$bul."\\\",$_'.$islem.'[$ad]); 
                } 
            } 
    ...
    }

    [url=http://www.phpclasses.org/browse/file/35305.html]Basic SQL Injection Protection[/url]
    Cleanup harmful text from request parameters

    Взято с phpclasses.org.
    Новый тип говнокода- турецкий(описание: расходится по швам при первой носке)

    А чё, ... не попортим так хакнем ;D

    AlexanderC, 10 Июня 2011

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

    +156

    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
    // ...html-параша и верстка таблицей	
    <?php
    	
    	if (isset($charsetList)) {
    		echo "<tr>";
    		echo "<td class=\"inputfield\">";
    		echo __("Charset") . ":";
    		echo "</td>";
    		echo "<td>";
    		echo "<select id=\"DBCHARSET\">";
    		echo "<option></option>";
    		
    		$defaultCharSql = $conn->query("SHOW VARIABLES LIKE 'character_set_server'");
    		
    		if ($conn->isResultSet($defaultCharSql)) {
    			$defaultCharset = $conn->result($defaultCharSql, 0, "Value");
    		}
    		
    		foreach ($charsetList as $charset) {
    			echo "<option value=\"" . $charset . "\"";
    			
    			if (isset($defaultCharset) && $charset == $defaultCharset) {
    				echo ' selected="selected"';
    			}
    			
    			echo ">" . $charset . "</option>";
    		}
    		echo "</select>";
    		echo "</td>";
    		echo "</tr>";
    	}
    	
    	?>
    // ... html-параша

    Кусок кода системы управления MySQL. http://www.sqlbuddy.com/
    Посмотрел в код и потянуло блевать.

    Yurik, 03 Июня 2011

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

    +156

    1. 1
    $value['VALUE'] = htmlspecialchars(str_replace(array("<",">"), "\"", $value['VALUE']));

    Безопасность на высоте. То, что потом приходят совершенно нечитаемые данные -- это ничего.

    ftr, 26 Мая 2011

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

    +156

    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
    class CLoader
    {
    	protected static $_importPaths = array(APPLICATION_PATH);
    	
    	public static function import($path)
    	{
    		self::$_importPaths[] = APPLICATION_PATH . '/' . $path;
    	}
    	
    	public function classExist($className)
    	{
    		return class_exists($className) || interface_exists($className);
    	}
    	
    	public static function autoload($className)
    	{
    		foreach(self::$_importPaths as $path)
    		{
    			if(is_file($fileName = $path . '/' . $className . '.php'))
    			{
    				include $fileName;
    				break;
    			}
    		}
    	}
    }
    
    spl_autoload_register(array('CLoader', 'autoload'));

    Гавнокод или нет? Идея в том, чтобы нормально можно было написать if(CLoader::classExist('Router'))...

    Может я чего не дочитал, но если добавлять пути с либами в include_path, а в функции autoload просто писать include $className . '.php', то class_exists('Router') выкинет ошибку, если файл Router.php не найден.

    Jetti, 09 Мая 2011

    Комментарии (11)
  8. JavaScript / Говнокод #6553

    +156

    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
    function newImage(arg) {
        if (document.images) {
            rslt = new Image();
            rslt.src = arg;
            return rslt;
        }
    }
    
    function preloadImages() {
              newImage("bigphoto/kran.jpg");
              newImage("bigphoto/z1.jpg");
              newImage("bigphoto/z2.jpg");
              newImage("bigphoto/truba.jpg");
              newImage("bigphoto/put.jpg");
    }

    moonie, 05 Мая 2011

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function check() {
    
    if (document.login.user.value == "user" &&
    document.login.password.value == "correct_password")
        window.location.href = 'http://this.site/login.html';
    else
        window.location.href = 'http://this.site/loginfehler.html';
    
    return false;
    }

    Функция входа, хуле

    jQuery, 24 Апреля 2011

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

    +156

    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
    //было:
    	function query($sque){
    		$sque = mysql_real_escape_string($sque,$this->hdb);
    		$res = mysql_query($sque,$this->hdb);
    		if(!$res){
    			echo 'Invalid query: '.mysql_error().'; ';
    			return 0;
    		}
    		return $res;
    	}
    //добавил:
    //так как предыдущая функция иногда косячила запрос
    	function sensiblequery($sque,$arr){
    		for($i = 0; $i<count($arr); ++$i){
    			$arr[$i] = mysql_real_escape_string($arr[$i],$this->hdb);
    			$pattern = "/{var$i}/";
    			$sque = preg_replace($pattern, $arr[$i], $sque);	
    		}
    		$res = mysql_query($sque,$this->hdb);
    		if(!$res){
    			echo 'Invalid query: '.mysql_error().'; ';
    			return 0;
    		}
    		return $res;
    	}

    Такое ощущение что написал говно. Если это так подскажите как адекватней сделать...

    greshnik, 23 Апреля 2011

    Комментарии (24)
  11. JavaScript / Говнокод #6433

    +156

    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
    // #1
    this.vml_capable = (document.all && !(navigator.userAgent.indexOf("Opera")>=0)) ? true : false;
    
    // #2
    styleSheet.addRule("v\\: *", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:roundrect", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:oval", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:roundrect", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:fill", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:line", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:shape", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:polyline", "behavior:url(#default#VML); position:absolute" );
    styleSheet.addRule("v\\:stroke", "behavior:url(#default#VML); position:absolute" );

    Библиотека svg2vml

    albburtsev, 21 Апреля 2011

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