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

    +158.1

    1. 1
    2. 2
    3. 3
    4. 4
    function fDim($m){
        $vDim = array(1, 3, 5, 7, 8, 10, 12);
        return (in_array($m, $vDim) ? 31 : ($m == 2? 28 : 30));
    }

    Функция возвращает количество дней в месяце. Очень забавный пассаж, ага?

    sharpstream, 10 Августа 2009

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

    +154

    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
    if ( isset( $criterias['name'] ) && ($criterias['name'] = trim( $criterias['name'] )) )
    {
    	$conditions .= empty( $conditions ) ? '(' : ' AND ';
    	$conditions .= "name LIKE '%".addslashes( $criterias['name'] )."%'";
    }
    
    if ( isset( $criterias['address'] ) && ($criterias['address'] = trim( $criterias['address'] )) )
    {
    	$conditions .= empty( $conditions ) ? '(' : ' AND ';
    	$conditions .= "address LIKE '%".addslashes( $criterias['address'] )."%'";
    }
    
    // если условие непустое, то закрываем скобку
    $conditions .= empty( $conditions ) ? '' : ')';

    Вместо использования массива для условий и последующего его объединения

    wunge, 10 Августа 2009

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

    +157.1

    1. 1
    return strtoupper(strtr($str, "йцукенгшщзхъэждлорпавыфячсмитьбюё", "ЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮЁ"));

    1C-Bitrix, вот говнищще-то!

    xEviL, 10 Августа 2009

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

    +129.4

    1. 1
    (string) $def == (string) $value

    Видимо о том, что == сравнивает строковые представления программист не знал.

    guest, 09 Августа 2009

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

    +131.3

    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
    function key_check($key) {
     if ($key == '') { return ''; }
     $key = preg_replace("/[^\w\xB2-\xB4\xBF-\xFF\xA5\xA8\xAA\xAF\xB8\xBA\s]/", "", $key );
     if ($key =='_SERVER' OR $key =='_SESSION' OR $key =='_FILES' OR $key =='_REQUEST' OR $key =='GLOBALS') die("<h3>Error variable ".basename(__FILE__)." ".__LINE__."</h3>");
     else return $key;
    }
    
    function str_check($str_val) {
    if ($str_val == '') { return ''; }
                    if(preg_match("/<[^>]*script*\"?[^>]*>/i", $str_val)
                    or preg_match("/<[^>]*object*\"?[^>]*>/i", $str_val)
                    or preg_match("/<[^>]*applet*\"?[^>]*>/i", $str_val)
                    or preg_match("/<[^>]*form*\"?[^>]*>/i"  , $str_val)
                    or preg_match("/&#\d+;{0,1}/i"  , $str_val) ){
                                    die("<h3>ERROR ".basename(__FILE__)." ".__LINE__."</h3>");
                    }
      $str_val = str_replace( "&"            , '&amp;'                 , $str_val );
      $str_val = str_replace( "<!--"         , '&#60;!--'              , $str_val );
      $str_val = str_replace( "-->"          , '--&#62;'               , $str_val );
      $str_val = str_replace( ">"            , '&gt;'                  , $str_val );
      $str_val = str_replace( "<"            , '&lt;'                  , $str_val );
      $str_val = str_replace( "\""           , '&quot;'                , $str_val );
      $str_val = str_replace( "\r"           , null                    , $str_val );
      $str_val = str_notsqlatacs($str_val);
      if (!get_magic_quotes_gpc()){$str_val=addslashes($str_val);}
      return $str_val;
    }
    function str_notsqlatacs($str_val) {
    $searcharray =array('/drop/i','/delete/i','/union/i','/char/i','/benchmark/i','/expression/i','/alert/i','/replace/i','/write/i','/document/i','/window/i','/script/i','/user_pass/i','/unescape/i','/eval/i','/form/i','/applet/i','/object/i','/user_login/i','/setTimeout/i','/onerror/i');
    $replacearray=array('&#100;rop','&#100;elete','&#117;nion','&#99;har','&#98;enchmark','&#69;xpression','&#65;lert','&#82;eplace','&#87;rite','&#68;ocument','&#87;indow','&#83;cript','&#85;ser_pass','&#85;nescape','&#69;val','&#70;orm','&#65;pplet','&#79;bject','&#85;ser_login','/&#83;etTimeout/i','/&#79;nerror/i');//
    $str_val=preg_replace($searcharray, $replacearray, $str_val);
      return $str_val;
    }

    Фрагмент файла ./php/wojs.php "портального движка" WebCodePortalSystem версии 5.2. И вот так вся CMSка - два с половиной мегабайта говна.

    guest, 07 Августа 2009

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

    +158.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    //...
    if (!count($error)) {
            if(strpos($msg,'samp.ucoz')) $msg = htmlSpecialChars('>>>>>>>>>>>{ Я ДАЛБОЁБ }<<<<<<<<<<<<<');
            if(strpos(strtoupper($msg),'GAMES.SHOP777')) $msg = htmlSpecialChars('>>>>>>>>>>>{ Я ДАЛБОЁБ }<<<<<<<<<<<<<');
            $DB->query("INSERT INTO `guestbook` (`user_id`,`user_name`,`msg`,`add_date`,`ip`) VALUES ('$user_id','$user_name','$msg',NOW(),'$ip')");
            header("Location: guestbook.php"); exit;
    }
    //...
    ?>

    Защита от спама :))
    Не, ну а чё, задолбали!

    guest, 07 Августа 2009

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

    +142.5

    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
    $out="<table valign=top>";
    for($k = 0; $k <= 6; $k += 1){     
        $sql="SELECT * FROM user_news1 ORDER BY date DESC LIMIT ".$k.",1";         
        $query=mysql_query($sql);
        $out.="<tr>";     
        while ($res=mysql_fetch_assoc($query)){
         $out.="<td style='vertical-align:top'>
               <div class=newsblock>
               <div class=newsdate>".date("d.m.Y G:i",strtotime($res['date']))."</div>
               <div class=newschapter><a href='/news/".$res['id'].".html'>".$res['header']."</a></div>
               ".($res['photo']!= '' ? " <a href='/news/".$res['id']."'><img src=/".str_replace(".", "_small.", $res['photo'])." class=imgnews border=0 align=left></a> " : "")."
               <div>".$res['announce']."</div></td>";
         }
        
        $out.="</tr>";
    }    
    $out.="</table>";
    
    
    echo $out;

    Вот как надо новости выводить:)

    guest, 07 Августа 2009

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

    +151.4

    1. 1
    2. 2
    3. 3
    if (isset($_SESSION) && !is_array($_SESSION)){
     exit("Hacking attempt");
    }

    просто улыбнуло
    симпатичная антихакерская защита

    guest, 07 Августа 2009

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

    +136.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function lock_user($id)
    {       
            global $db_obj;
     
            $SQL = "SELECT GET_LOCK('%s', 10)";
            $SQL = sprintf($SQL, (int)$id);
            $result = $db_obj->query($SQL);
            $row = $db_obj->fetch_array($result);
            $key = "GET_LOCK('" . (int)($id) . "', 10)";
            $res = $row[$key];
            return $res;
    }

    дзен

    guest, 06 Августа 2009

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

    +135.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Validate numeric field
    public function validateNumber($field, $errorMessage, $min=2, $max=32){
        if(!isset($_REQUEST[$field]) || !is_numeric($_REQUEST[$field]) 
            || strlen($_REQUEST[$field])<$min 
            || strlen($_REQUEST[$field])>$max)
        {
            $this->errors[]=str_replace('<br>', '', $errorMessage) . '<br>';
        }
    }

    Legacy код от индусов. Строки 4-5 просто лучшие.

    guest, 06 Августа 2009

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