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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?
    function save($author,$title,$pubyear,$price) {
            $sql = "INSERT INTO catalog(author,title,pubyear,price) 
                            VALUES('$author','$title',$pubyear,$price)";
            mysql_query($sql) or die (mysql_error());
    }
     function selectAll() {
                    $sql = "SELECT * FROM catalog";
                    $result = mysql_query($sql) or die(mysql_error());
                    return $result;
    }

    qbasic, 17 Марта 2011

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $pattern = "/\w{0,5}[хx]([хx\s\!@#\$%\^&*+-\|\/]{0,6})[уy]([уy\s\!@#\$%\^&*+-\|\/]{0,6})
    [ёiлeеюийя]\w{0,7}|\w{0,6}[пp]([пp\s\!@#\$%\^&*+-\|\/]{0,6})[iие]([iие\s\!@#\$%\^&*+-\|\/]{0,6})
    [3зс]([3зс\s\!@#\$%\^&*+-\|\/]{0,6})[дd]\w{0,10}|[сcs][уy]([уy\!@#\$%\^&*+-\|\/]{0,6})[4чkк]\w{1,3}
    |\w{0,4}[bб]([bб\s\!@#\$%\^&*+-\|\/]{0,6})[lл]([lл\s\!@#\$%\^&*+-\|\/]{0,6})[yя]\w{0,10}|\w{0,8}[её][bб]
    [лске@eыиаa][наи@йвл]\w{0,8}|\w{0,4}[еe]([еe\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})[uу]
    ([uу\s\!@#\$%\^&*+-\|\/]{0,6})[н4ч]\w{0,4}|\w{0,4}[еeё]([еeё\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})
    [нn]([нn\s\!@#\$%\^&*+-\|\/]{0,6})[уy]\w{0,4}|\w{0,4}[еe]([еe\s\!@#\$%\^&*+-\|\/]{0,6})[бb]([бb\s\!@#\$%\^&*+-\|\/]{0,6})
    [оoаa@]([оoаa@\s\!@#\$%\^&*+-\|\/]{0,6})[тnнt]\w{0,4}|\w{0,10}[ё]([ё\!@#\$%\^&*+-\|\/]{0,6})[б]\w{0,6}|\w{0,4}[pп]
    ([pп\s\!@#\$%\^&*+-\|\/]{0,6})[иeеi]([иeеi\s\!@#\$%\^&*+-\|\/]{0,6})[дd]([дd\s\!@#\$%\^&*+-\|\/]{0,6})
    [oоаa@еeиi]([oоаa@еeиi\s\!@#\$%\^&*+-\|\/]{0,6})[рr]\w{0,12}/i";

    Думал навсегда потерял, а вчера случайно нашел в мемориз на одном из сайтов. Кусок этот встретил лет семь назад.

    Rpsl, 17 Марта 2011

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function printVar($var) {
        ob_start();
        print_r($var);
        $var = ob_get_contents();
        ob_end_clean();
        return $var;
     }

    Вдруг версия php < 4.2.0? :)
    Найдено в фреймворке DoPHP

    PANACEA, 17 Марта 2011

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

    +149

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $message = array(
    		'Message from blablabla',
    		'',
    		'Name: '.$_POST['name'],
    		'Title: '.$_POST['title'],
    		'City, State: '.$_POST['city'],
    		'Enrollment: '.$_POST['enrol'],
    		'Email: '.$_POST['email'],
    		'Phone: '.$_POST['phone'],
    	);
    	$body = implode('<br>',$message);

    Чувак, вроде опытный программист, в 2006 году написал сие произведение искусства:

    twtwtw, 16 Марта 2011

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function ValidateIPAdress($value){
        if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $value)){
            return true;
        }
        return false;
    }
    if( ValidateIPAdress("192.168.0.1") )
        echo("This is an IPAdress");
    else
        echo("This is not an IPAdress");

    Функция проверки IP адреса.

    vdmodule, 16 Марта 2011

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

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
    	 * Test to see if the cache storage is available.
    	 *
    	 * @static
    	 * @access public
    	 * @return boolean  True on success, false otherwise.
    	 */
    	function test()
    	{
    		return true;
    	}

    Описание метода в коментах.
    Joomfish

    tranquillity, 16 Марта 2011

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

    +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
    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
    elseif( $action == "pingationmod" ) { 
    echoheader( "options", "pingationMod" ); 
    echo <<<HTML 
    <form action="{$PHP_SELF}" method="post"> 
    <div style="padding-top:5px;padding-bottom:2px;"> 
    <table width="100%"> 
    <tr> 
    <td width="4"><img src="engine/skins/images/tl_lo.gif" width="4" height="4" border="0"></td> 
    <td background="engine/skins/images/tl_oo.gif"><img src="engine/skins/images/tl_oo.gif" width="1" height="4" border="0"></td> 
    <td width="6"><img src="engine/skins/images/tl_ro.gif" width="6" height="4" border="0"></td> 
    </tr> 
    <tr> 
    <td background="engine/skins/images/tl_lb.gif"><img src="engine/skins/images/tl_lb.gif" width="4" height="1" border="0"></td> 
    <td style="padding:5px;" bgcolor="#FFFFFF"> 
    <table width="100%"> 
    <tr> 
    <td bgcolor="#EFEFEF" height="29" style="padding-left:10px;"><div class="navigation">Отправка уведомлений в пинг сервисы</div></td> 
    </tr> 
    </table> 
    <div class="unterline"></div> 
    <table width="100%"> 
    <tr> 
    <td style="padding:2px;" height="100" align="center"> 
    HTML; 
         
    echo "Вы действительно хотите отправить уведомления в пинг сервисы, на (<b>" . count( $selected_news ). "</b>) $lang[mass_confirm_1]<br><br> 
    <input class=bbcodes type=submit value=\"   $lang[mass_yes]   \"> &nbsp; <input type=button class=bbcodes value=\"  $lang[mass_no]  \" onclick=\"javascript:document.location='$PHP_SELF?mod=editnews&action=list'\"> 
    <input type=hidden name=action value=\"do_mass_ping\"> 
    <input type=hidden name=user_hash value=\"{$dle_login_hash}\"> 
    <input type=hidden name=mod value=\"massactions\">"; 
    foreach ( $selected_news as $newsid ) { 
    $newsid = intval($newsid); 
    echo "<input type=hidden name=selected_news[] value=\"$newsid\">"; 
    } 
    echo <<<HTML 
    </tr> 
    </table> 
    </td> 
    <td background="engine/skins/images/tl_rb.gif"><img src="engine/skins/images/tl_rb.gif" width="6" height="1" border="0"></td> 
    </tr> 
    <tr> 
    <td><img src="engine/skins/images/tl_lu.gif" width="4" height="6" border="0"></td> 
    <td background="engine/skins/images/tl_ub.gif"><img src="engine/skins/images/tl_ub.gif" width="1" height="6" border="0"></td> 
    <td><img src="engine/skins/images/tl_ru.gif" width="6" height="6" border="0"></td> 
    </tr> 
    </table> 
    </div></form> 
    HTML; 
    echofooter(); 
    exit(); 
    }elseif( $action == "do_mass_ping" ) { 
    include ENGINE_DIR .'/inc/include/pingfunction.php'; 
    include ENGINE_DIR .'/data/pingdata.php'; 
    foreach ( $selected_news as $newsid ) { 
    $newsid = intval($newsid); 
    $sql_select = "SELECT id, title, date, category, alt_name, flag FROM ".PREFIX ."_post WHERE id=".$newsid; 
    $sql_result = $db->query( $sql_select ); 
    while ( $row = $db->get_row( $sql_result ) ) { 
    $row['date'] = strtotime( $row['date'] ); 
    $title = $row['title']; 
    if( $config['allow_alt_url'] == "yes") { 
    if( $row['flag'] and $config['seo_type'] ) { 
    if( $row['category'] and $config['seo_type'] == 2 ) { 
    $full_link = $config['http_home_url'] .get_url( $row['category'] ) ."/".$row['id'] ."-".$row['alt_name'] .".html"; 
    }else { 
    $full_link = $config['http_home_url'] .$row['id'] ."-".$row['alt_name'] .".html"; 
    } 
    }else { 
    $full_link = $config['http_home_url'] .date( 'Y/m/d/',$row['date'] ) .$row['alt_name'] .".html"; 
    } 
    }else { 
    $full_link = $config['http_home_url'] ."index.php?newsid=".$row['id']; 
    } 
    } 
    pingationMod($title, $full_link, 0, $pingdata['service'], $pingdata['zaderjka']); 
    } 
    if($pingdata['allow_log']){ 
     
    saveLog("Массовая отправка уведомлений в пинг сервисы"); 
    } 
     
    clear_cache(); 
    msg( "info", "Уведомления успешно отправлены", "Уведомления успешно отправлены в пинг сервисы", $_SESSION['admin_referrer'] ); 
    }

    qbasic, 16 Марта 2011

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    header('Content-Type: text/plain; charset=windows-1251'); // текстовый формат... что бы переносы строки нормально отображались и ширина букв была одинаковая
    
    function CheckDir($s,$step)
    {
            echo str_repeat('-',$step).basename($s)."\r\n"; 
            $a = glob($s.'/*',GLOB_ONLYDIR);
            foreach($a as $v)
            {
                    CheckDir($v,$step+1); 
            }
    }

    qbasic, 16 Марта 2011

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

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function generateGUID ()
      {
          $GUID = $this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter()."-";
          $GUID = $GUID.$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter().$this->generateCharacter();
          return $GUID;
      }

    из класса для работы с paypal. (скачан с оффсайта)

    newmindcore, 16 Марта 2011

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

    +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
    function price_filter_form()
    {
        // Хуярим неиибически сложную систему фильтрации по цене:
        $sql = "
    SELECT
    Max(c_good.price) AS `max`,
    Min(c_good.price) AS `min`,
    Count(c_good.price) AS `count`
    FROM
    c_good
    WHERE
    c_good.podcat_id =  '".mysql_real_escape_string($_GET['id'])."' AND
    c_good.onoff =  '1' AND c_good.`check` = '1'";
        $sql = mysql_query($sql) OR DIE (log_error('sql'));
        $price = mysql_fetch_assoc($sql);
        #echo ("<pre>");
        #print_r($price);
        #echo ("</pre>");
        if ($price['count'] < '10') // если товаров меньше 10, выводим 1 диапазон цен
        {
         $price_form = "<option value=\"".$price['min'].":".$price['max']."\">".$price['min']."-".$price['max']."руб.</option>";    
        }
        else
        {
            // Далее идёт непонятный говнокод, который к удивлению работает
            $step = (($price['max']-$price['min'])/11);
            $step = ceil($step);
            $step_len = strlen($step);
            $step = round($step, -($step_len-1));
            $first_step = ($price['min']+$step);
            $first_step_len = strlen($first_step);
            $first_step = (round($first_step, -($first_step_len-2))-1);
            #if ($first_step < $price['min']) $first_step = $price['min']+$step;
            $price_form = "<option value=\"".$price['min'].":".$first_step."\">".$price['min']."-".$first_step."руб.</option>";
            $price_form .= "<option value=\"".($first_step+1).":".($first_step+$step)."\">".($first_step+1)."-".($first_step+$step)."руб.</option>";
            
            #echo $step;
            for ($i=1;$i<8;$i++)
            {
             $price_form .= "<option value=\"".($first_step+($step*$i)+1).":".($first_step+($step*($i+1)))."\">
             ".($first_step+($step*$i)+1)."-".($first_step+($step*($i+1)))."руб.</option>";    
            }
            $price_form .= "<option value=\"".($first_step+($step*8)+1).":".$price['max']."\">
            ".($first_step+($step*8)+1)."-".$price['max']."руб.</option>";
        }
        $price_form = str_replace("\"".$defult_price['1']."\"", "\"".$defult_price['1']."\" selected", $price_form);
        return $price_form;
    }
    ?>

    вот с таким ГК пришлось столкнуться, после профилирования. Как Вам? Или - это нормально для PHP???
    P.S. комментарии сохранены авторские.

    ZeiZ, 16 Марта 2011

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