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

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

    +54

    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
    function bezpezdu_num($num)
    {
    	if(isset($num) && !empty($num) && is_numeric($num))
    		return true;
    	else
    		return false;
    }
    
    function pizdec($text)
    {
    	$showtext = htmlspecialchars($text);
    	exit($showtext);
    }

    $app->run_epta();

    kindofbear, 21 Декабря 2012

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

    +54

    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
    function validEmail($email)
    {
    	$isValid = true;
    	$atIndex = strrpos($email, "@");
    	if (is_bool($atIndex) && !$atIndex) {
    		$isValid = false;
    	} else {
    		$domain = substr($email, $atIndex + 1);
    		$local = substr($email, 0, $atIndex);
    		$localLen = strlen($local);
    		$domainLen = strlen($domain);
    		if ($localLen < 1 || $localLen > 64) {
    			// local part length exceeded
    			$isValid = false;
    		} else if ($domainLen < 1 || $domainLen > 255) {
    			// domain part length exceeded
    			$isValid = false;
    		} else if (!strrpos($domain, ".")) {
    			// domain part does not have .
    			$isValid = false;
    		} else if ($domain[0] == '.' || $domain[$domainLen - 1] == '.') {
    			// domain part starts or ends with '.'
    			$isValid = false;
    		} else if ($local[0] == '.' || $local[$localLen - 1] == '.') {
    			// local part starts or ends with '.'
    			$isValid = false;
    		} else if (preg_match('/\\.\\./', $local)) {
    			// local part has two consecutive dots
    			$isValid = false;
    		} else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
    			// character not valid in domain part
    			$isValid = false;
    		} else if (preg_match('/\\.\\./', $domain)) {
    			// domain part has two consecutive dots
    			$isValid = false;
    		} else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) {
    			// character not valid in local part unless 
    			// local part is quoted
    			if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) {
    				$isValid = false;
    			}
    		}
    		/* if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
    		  // domain not found in DNS
    		  $isValid = false;
    		  } */
    	}
    	return $isValid;
    }

    Интересно а автор когдата слишал про filter_var?
    Это все можна заменить на filter_var($input, FILTER_VALIDATE_EMAIL);
    Товаришь программист! Не умеешь срать - не мучай жопу!

    v_anonym, 19 Декабря 2012

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

    +54

    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
    if($i!='0')
                {
                        $query="SELECT DATE_ADD(CURDATE(), INTERVAL ".$i." MONTH)";
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date_newmonth=$temp_date_array[0];
                       
                        $query="SELECT DAYOFMONTH('".$temp_date_newmonth."');";
                        $day=mysql_fetch_row(mysql_query($query));
                       
                        $query="SELECT DATE_ADD('".$temp_date_newmonth."', INTERVAL -".($day[0]-1)." DAY)";
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date=$temp_date_array[0];
                       
                        $query="SELECT DATE_ADD('".$temp_date."', INTERVAL 1 MONTH);";
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date_end=$temp_date_array[0];
                }
                else
                {
                        $query="SELECT CURDATE();";    
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date=$temp_date_array[0];
                       
                        $query="SELECT DAYOFMONTH('".$temp_date."');";
                        $day=mysql_fetch_row(mysql_query($query));
                       
                        $query="SELECT DATE_ADD(CURDATE(), INTERVAL 1 MONTH)";
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date_end_newmonth=$temp_date_array[0];
                       
                        $query="SELECT DATE_ADD('".$temp_date_end_newmonth."', INTERVAL -".($day[0]-1)." DAY)";
                        $temp_date_array=mysql_fetch_row(mysql_query($query));
                        $temp_date_end=$temp_date_array[0];
                }
                $query="SELECT MONTH('".$temp_date."');";

    http://forum.php.su/topic.php?forum=69&topic=50&v=#135410099 3

    sKaa, 28 Ноября 2012

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

    +54

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $postitle = str_replace (' ', '-', $title);
    				$postitle = str_replace ('/', '', $postitle);
    				$postitle = str_replace ('\\', '', $postitle);
    				$postitle = str_replace (':', '', $postitle);
    				$postitle = str_replace ('<', '', $postitle);
    				$postitle = str_replace ('>', '', $postitle);
    				$postitle = str_replace ('*', '', $postitle);
    				$postitle = str_replace ('?', '', $postitle);
    				$postitle = str_replace ('|', '', $postitle);
    				$postitle = str_replace ('"', '', $postitle);
    				$postitle = preg_replace ('#\[.*?\]#isu', '', $postitle);

    aleksey, 14 Ноября 2012

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $res = mysql_query("SELECT * FROM `users`");
    while ($arr = mysql_fetch_assoc($res))
    {
    	$res1 = mysql_query("SELECT * FROM `cabinet_users` WHERE `nick`='$arr[user]'");
    	$arr1 = mysql_fetch_assoc($res1);
            ...
    }

    JOIN'ы для слабаков.

    UnnamedUser, 10 Ноября 2012

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

    +54

    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
    function mail_mime_to_array($imap,$mid,$parse_headers=false) 
             { 
    
                 $mail = imap_fetchstructure($imap,$mid);
    
                    // ИМЕННО ПОЧИНИЛ
                    if(!isset($mail->parts))  {
    
                            $mail->parts = array();
                            $mail->parts[0]['type'] = $mail->type;
                            $mail->parts[0]['encoding'] = $mail->encoding;
                            $mail->parts[0]['ifsubtype'] = $mail->ifsubtype;
                            $mail->parts[0]['subtype'] = $mail->subtype;
                            $mail->parts[0]['ifdescription'] = $mail->ifdescription;
                            $mail->parts[0]['ifid'] = $mail->ifid;
                            $mail->parts[0]['bytes'] = $mail->bytes;
                            $mail->parts[0]['ifdisposition'] = $mail->ifdisposition;
                            $mail->parts[0]['disposition'] = $mail->disposition;
                            $mail->parts[0]['ifdparameters'] =$mail->ifdparameters;
                            $mail->parts[0]['dparameters'] =$mail->dparameters;
                            $mail->parts[0]['ifparameters'] =$mail->ifparameters;
                            $mail->parts[0]['parameters'] =$mail->parameters;
    
                    }
    
                 $mail = mail_get_parts($imap,$mid,$mail,0); 
    
      
                    // ИМЕННО ПОЧИНИЛ
                    if(!isset($mail->parts))  {
    
                        $mail[1]['data'] = imap_base64($mail[1]['data']);  
                    }
    
                 if ($parse_headers) $mail[0]["parsed"]=mail_parse_headers($mail[0]["data"]); 
    
                 return($mail); 
    
             }

    мое говно-детище

    АЙФОН к примеру не отправляет заголовки и я не мог правильно под него запарсить вложения к почтовому сообщению.
    Решил не париться и именно починил, взял скотч решил эту проблему, просто залепил ее.

    Самое обидное, что даже не знаю как ее по нормальному решить.

    nepster, 01 Октября 2012

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

    +54

    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
    function viewMap ($battleid, $userplace, $oppo) {
        $map = Base("sel", "*", "battlemap", $battleid, 'battleid');
        $x=0;
        $stringcount=1;
        $string2=0;
        while ((isset($map[$x]['battlemap_id']))) {
            if((fmod($stringcount,15)==1)&&(fmod($stringcount,2)==1)) {
                $content.='<div style="position:relative;float:left; border:none; width:750px;">';//начало нечётной строки
                $string2++;
            }
            if((fmod($stringcount,15)==1)&&(fmod($stringcount,2)==0)) {
                $content.='<div style="position:relative;float:left; border:none;margin-left:25px; width:750px;margin-top:0px;">';//начало чётной строки
                $string2++;
            }
            $content.='<div style="position:relative;float:left;width:50px;height:50px;border:none;">';
    
            if (($map[$x]['battlemap_patterntype']==0)&&($oppo['user_battlemap']!=$map[$x]['battlemap_cellnumber'])&&($userplace!= $map[$x]['battlemap_cellnumber'])) {/*а теперь брутальная анальная дефлорация ослиц от графа(не пытайтесь повторить)*/
                $xuy=$x+1;
                if((fmod($string2,2)==0)and(!isset($shotflag)))//ежели мы не стреляем и пляшем в чётной строке, а перс в нечётной
                {
                    if(($x==($userplace-17))or($x==($userplace-16))or($x==($userplace+14))or($x==($userplace+13))) {
                        $content .='<a href="javascript:gogo('.$xuy.')">';
                    }
                }
                if((fmod($string2,2)==1)and(!isset($shotflag)))//ежели мы не стреляем и пляшем в нечётной строке, а перс в чётной
                {
                    if(($x==($userplace-16))or($x==($userplace-15))or($x==($userplace+15))or($x==($userplace+14))) {
                        $content .='<a href="javascript:gogo('.$xuy.')">';
                    }
                }
                if(($map[$x]['battlemap_cellnumber']==($userplace-1))or($map[$x]['battlemap_cellnumber']==($userplace+1))) {
                    $content .='<a href="javascript:gogo('.$xuy.')">';
                }
                $content .='<div style="position:relative;float:left;background-image:url(/img/patterns/'.$map[$x]['battlemap_patterntype'].$map[$x]['battlemap_patternstr'].'.png);height: 50px; width: 50px;"><br/> '.$map[$x]['battlemap_cellnumber'].'</div>';
                /*всё та же дефлорация*/
                if(($map[$x]['battlemap_cellnumber']==($userplace-1))or($map[$x]['battlemap_cellnumber']==($userplace+1))) {
                    $content .='</a>';
                }
                if(fmod($string2,2)==0)//ежели господа пляшем в чётной строке, а перс в нечётной
                {
                    if(($x==($userplace-17))or($x==($userplace-16))or($x==($userplace+14))or($x==($userplace+13))) {
                        $content .='</a>';
                    }
                }
                if(fmod($string2,2)==1)//ежели господа пляшем в нечётной строке, а перс в чётной
                {
                    if(($x==($userplace-16))or($x==($userplace-15))or($x==($userplace+15))or($x==($userplace+14))) {
                        $content .='</a>';
                    }
                }
            }
            if($userplace == $map[$x]['battlemap_cellnumber']) {
                $content .='<a target="_top" href="spell.php?login='.$oppo['user_login'].'" target="_parent" title="Заклинания\Способности" rel="gb_page_center[660, 180]"><div style="position:relative;float:left;background-image:url(/img/patterns/hero.png);height: 50px; width: 50px;"><br/> hero<br/>'.$stringcount2.'</div></a>';
            }
    
            if($oppo['user_battlemap'] ==$map[$x]['battlemap_cellnumber']) {
                $content .='<a href="spell.php?bgo_id='.$map[$x]['battlemap_cellnumber'].'&action=cast">Скастовать</a><br/>
    <a href="index.php?bgo_id='.$map[$x]['battlemap_cellnumber'].'&action=shoot">Выстрелить</a><br/>
        <a target="_top" href="info.php?login='.$oppo['user_login'].'" target="_parent" title="Информация о пользователе" rel="gb_page_center[460, 480]">
        <div style="position:relative;float:left;background-image:url(/img/patterns/hero.png);height: 50px; width: 50px;"><br/> oppo</div></a>';
            }
    
            $content .= '</div>';//конец ячейки
            if(fmod($stringcount,15)==0) {
                $content.='</div>';//конец строки
            }
            $x++;
            $stringcount++;
        }
        echo '<div style="margin-top:80px; margin-left:65px; owerflow:hidden;position:relative;width:777px; height:500px; float:left; border:none; background-image:url(http://steambox.ru/img/battlebackgrounds/'.$map[0]['battlemap_landtype'].'.png);background-repeat:no-repeat;">'
                .$content.
                '</div>'
        ;
    }

    Кусок браузерки. Весь остальной код в том же духе (http://govnokod.ru/9458, http://govnokod.ru/3103, http://govnokod.ru/3101 ).
    Около 110000 строк отборного говнокода. И как то умудрялось все работать. Недолго правда)))

    WinnerWolf, 08 Сентября 2012

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

    +54

    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
    <?php
    
    class SimpleController extends Zend_Controller_Action
    {
        public function init()
        {
            $action = $this->_request->getActionName();
            $is_action_available = in_array($action, explode(',', 'terms,privacy,about,copyright,support,legal,features,help,refund'));
            $is_incorrect_action = CR_Settings::siteIsFree() && $action == 'refund';
            if (!$is_action_available || $is_incorrect_action)
                $this->_helper->redirector->setGotoRoute(array('action' => 'index'), 'default', true);
        }
        
        public function termsAction(){
        }
        
        public function privacyAction(){
        }
        
        public function aboutAction(){
        }
        
        public function copyrightAction(){
        }
        
        public function supportAction(){
        }
        
        public function legalAction(){
        }
        
        public function featuresAction(){
        }
        
        public function helpAction(){
        }
        
        public function refundAction(){
        }
    }

    Zend Framework проверка на существование action :)

    arkasha, 31 Августа 2012

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

    +54

    1. 1
    2. 2
    //Вычисляем предыдущий месяц
    $bdate = q1("SELECT '$cdate' - INTERVAL 1 MONTH");

    wds, 12 Июля 2012

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
         * Грабли - наше всьо
         * @return string
         */
        function toPage()
        {
            ...
        }

    прекрасно задокументированная функция

    shmaltorhbooks, 03 Июля 2012

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