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

    +151

    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
    //клас для отправления писем через smtp
    //способ приминения
    //функция хеадерс(ящик куда отправлять,ящик откуда отправляется,почтовик(пример @yandex.ru), тема письма)
    //$headers = $post->headers($users[$i]."@yandex.ru",$users[$i]."@yandex.ru","@yandex.ru",$result['title']);
    //функция отправка (текст письма, заголовок, ящик получателя, адрес отправителя,имя пользователя, пароль, домен почтовика(пример yandex.ru))
    //$post->send($result_text,$headers,$users[$i]."@yandex.ru",$users[$i]."@yandex.ru",$users[$i],$pass[$i],"yandex.ru");
      class mailer
    {
    
        
      function get_data($smtp_conn)
      {
      $data="";
      while($str = fgets($smtp_conn,515))
      {
        $data .= $str;
        if(substr($str,3,1) == " ") { break; }
      }
      return $data;
      }
      
      
      
     function headers($to,$from,$prefix,$zag)
     { 
    $header="Date: ".date("D, j M Y G:i:s")." +0700\r\n";
    $header.="From: <".$from.">\r\n";
    $header.="X-Mailer: The Bat! (v3.99.3) Professional\r\n";
    $header.="X-Priority: 3 (Normal)\r\n";
    $header.="Message-ID: <172562218.".date("YmjHis").$prefix.">\r\n";
    $header.="To: <".$to.">\r\n";
    $header.="Subject: ".$zag."\r\n";
    $header.="MIME-Version: 1.0\r\n";
    $header.="Content-Type: text/html; charset=utf-8\r\n";
    $header.="Content-Transfer-Encoding: 8bit\r\n";
    return $header; 
     }
     
     
     
     function send($text, $header, $to, $from, $login , $pass, $mailer)
     {
     
      $fin = new mailer;
      
      
     $smtp_conn = fsockopen("smtp.".$mailer, 25,$errno, $errstr, 10);  
     $data = $fin->get_data($smtp_conn); 
      
     fputs($smtp_conn,"EHLO ".$mailer."\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,"AUTH LOGIN\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,base64_encode($login)."\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,base64_encode($pass)."\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,"MAIL FROM:".$from."\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,"RCPT TO:".$to."\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,"DATA\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,$header."\r\n".$text."\r\n.\r\n");
    $data = $fin->get_data($smtp_conn);
    
    fputs($smtp_conn,"QUIT\r\n");
    $data = $fin->get_data($smtp_conn);
    
    
     }
    
    }

    клас для отправления писем через smtp

    dodther, 12 Августа 2009

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

    +163.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $true = true;
    for ($i=0; $i<count($list); $i++)
      if (!isset($list[$i]))
       $true = false;
    
    if ($true != true)
      die ("Error");

    Немного о правде и лжи

    GreenSid, 11 Августа 2009

    Комментарии (8)
  3. C# / Говнокод #1535

    +138

    1. 1
    txtCollimator.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";

    Прапрапрадедушка можно уже не показывать.
    Дикая вложенность UserContol в ASP.Net дает о себе знать.

    vaceknt, 11 Августа 2009

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

    +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
    <?php
    ...
    
    $date1['year'] = ($_POST['year1']>=2006 && $_POST['year1']<=2037) ? $_POST['year1'] : (($_GET['year1']>=2006 && $_GET['year1']<=2037) ? $_GET['year1'] : date('Y'));
    $date1['month'] = ($_POST['month1']>=1 && $_POST['month1']<=12) ? $_POST['month1'] : (($_GET['month1']>=1 && $_GET['month1']<=12) ? $_GET['month1'] : date('n'));
    $date1['day'] = $type>2 ? 1 : (($_POST['day1']>=1 && $_POST['day1']<=31) ? $_POST['day1'] : (($_GET['day1']>=1 && $_GET['day1']<=31) ? $_GET['day1'] : date('j')));
    $date1['hour'] = $type>1 ? 0 : ((isset($_POST['hour1']) && $_POST['hour1']>=0 && $_POST['hour1']<=23) ? $_POST['hour1'] : ((isset($_GET['hour1']) && $_GET['hour1']>=0 && $_GET['hour1']<=23) ? $_GET['hour1'] : 0));
    $date1['min'] = $type ? 0 : ((isset($_POST['min1']) && $_POST['min1']>=0 && $_POST['min1']<=59) ? $_POST['min1'] : ((isset($_GET['min1']) && $_GET['min1']>=0 && $_GET['min1']<=59) ? $_GET['min1'] : 0));
    
    $date2['year'] = ($_POST['year2']>=2006 && $_POST['year2']<=2037) ? $_POST['year2'] : (($_GET['year2']>=2006 && $_GET['year2']<=2037) ? $_GET['year2'] : date('Y'));
    $date2['month'] = ($_POST['month2']>=1 && $_POST['month2']<=12) ? $_POST['month2'] : (($_GET['month2']>=1 && $_GET['month2']<=12) ? $_GET['month2'] : date('n'));
    $date2['day'] = $type>2 ? cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year']) : (($_POST['day2']>=1 && $_POST['day2']<=31) ? $_POST['day2'] : (($_GET['day2']>=1 && $_GET['day2']<=31) ? $_GET['day2'] : date('j')));
    $date2['hour'] = $type>1 ? 23 : ((isset($_POST['hour2']) && $_POST['hour2']>=0 && $_POST['hour2']<=23) ? $_POST['hour2'] : ((isset($_GET['hour2']) && $_GET['hour2']>=0 && $_GET['hour2']<=23) ? $_GET['hour2'] : 23));
    $date2['min'] = $type ? 59 : ((isset($_POST['min2']) && $_POST['min2']>=0 && $_POST['min2']<=59) ? $_POST['min2'] : ((isset($_GET['min2']) && $_GET['min2']>=0 && $_GET['min2']<=59) ? $_GET['min2'] : 59));
    
    $date1['day'] = cal_days_in_month(CAL_GREGORIAN, $date1['month'], $date1['year'])<$date1['day'] ? cal_days_in_month(CAL_GREGORIAN, $date1['month'], $date1['year']) : $date1['day'];
    $date2['day'] = cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year'])<$date2['day'] ? cal_days_in_month(CAL_GREGORIAN, $date2['month'], $date2['year']) : $date2['day'];
    
    $time_from = mktime($date1['hour'], $date1['min'], 1, $date1['month'], $date1['day'], $date1['year']);
    $time_to = mktime($date2['hour'], $date2['min'], 59, $date2['month'], $date2['day'], $date2['year']);
    
    $types = array(0,1,2,3);
    switch ($type) {
    	case 0:
    		$sql_cols = "minute(from_unixtime(data.log_time)) as \"i\", hour(from_unixtime(data.log_time)) as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "i", "G", "j", "n", "Y"';
    		break;
    	case 1:
    		$sql_cols = "'0' as \"i\", hour(from_unixtime(data.log_time)) as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "G", "j", "n", "Y"';
    		break;
    	case 2:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", day(from_unixtime(data.log_time)) as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "j", "n", "Y"';
    		break;
    	case 3:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", '0' as \"j\", month(from_unixtime(data.log_time)) as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "n", "Y"';
    		break;
    	default:
    		$sql_cols = "'0' as \"i\", '0' as \"G\", '0' as \"j\", '0' as \"n\", year(from_unixtime(data.log_time)) as \"Y\"";
    		$sql_group_by = 'group by "Y"';
    		$type = 2;
    }
    
    ...

    Писал "биллинг" попутно изучая пхп) скрипт вывода статистики

    PycmaM, 11 Августа 2009

    Комментарии (2)
  5. JavaScript / Говнокод #1533

    +144.9

    1. 1
    /a-z{3,}/.test(str);

    Проверка содержит ли функция 3 символа алфавита или больше.
    Правильно так: /[a-z]{3,}/

    Oleg_quadro, 11 Августа 2009

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

    +163.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $isLoginned = true;
    
    if (strlen(strval($isLoginned)) == 4) {
    } else {
    }

    В одном из опенсурсных форумов в исходниках видел

    chipfind, 11 Августа 2009

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

    +91.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    ...
          if DM.LastCOID <> -1 then
          begin
            if Pos(IntToStr(DM.LastCOID), Label1.Caption) <= 0 then
            begin
              Label1.Caption := 'Телефон: ' + '(' + IntToStr(DM.LastCOID) + ')';
              DataSet['CHANNELOUTERID'] := IntToStr(DM.LastCOID);
            end;
          end;
    ...

    LastCOID - номер внешней линии, который отображается в лейбле Label1 и заносится в поле базы. Как и чем думал автор вставляя второе условие? Самое главное, для чего? В итоге, софтина иногда пропускала сохранение LastCOID в БД, тем самым портя статистику и настроение клиента.

    ybinzu, 11 Августа 2009

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

    −117.2

    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
    my $cache_sql="SELECT `content`, `insertTime` FROM _cache WHERE `confid`='$$conf{confid}'";
    ...
        $cache_sql.=" AND `location`=".$self->{dbh}->quote($url);
    ...
        $cache_sql.=" AND `cgiparams`=".$self->{dbh}->quote($cgi_hash);
    ...
        $cache_sql.=" AND `callparams`=".$self->{dbh}->quote($callp_hash);
    ...
        $cache_sql.=" AND `userid`=".int($$params{userid});
    ...
        $cache_sql.=" AND `groupid`=".int($$params{groupid});
    
       my $replace_sql=$cache_sql;
       $replace_sql=~s/SELECT.*?FROM\s+_cache\s+WHERE/REPLACE INTO _cache SET/s;

    perl+sql

    poltora, 11 Августа 2009

    Комментарии (1)
  9. Perl / Говнокод #1529

    −101

    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
    my $iref=$self->{ditems}->_get_item({itemid=>$weather_itemid, set=>'Weather', fields=>['MinT', 'MaxT', 'Precip', 'Cloud', 'twater'], prefix=>$$p{prefix}});
        if ($$iref{$$p{prefix}.'MinT'}<0 && $$iref{$$p{prefix}.'MaxT'}<=0) {
            my $tmp=$$iref{$$p{prefix}.'MaxT'};
            $$iref{$$p{prefix}.'MaxT'}=$$iref{$$p{prefix}.'MinT'};
            $$iref{$$p{prefix}.'MaxT'}=$tmp;
        };
        #warn $$iref{$$p{prefix}.'MinT'} if !$$iref{$$p{prefix}.'MinT'}>0;
        $$iref{$$p{prefix}.'T'}=int( ($$iref{$$p{prefix}.'MinT'}+$$iref{$$p{prefix}.'MaxT'})/2 );
        $$iref{$$p{prefix}.'T'}='+'.$$iref{$$p{prefix}.'T'} if $$iref{$$p{prefix}.'T'}>0;
        #$$iref{$$p{prefix}.'T'}=~s/\-/\&\#150\;/gs;
        $$iref{$$p{prefix}.'MinT'}='+'.$$iref{$$p{prefix}.'MinT'} if ($$iref{$$p{prefix}.'MinT'}>0);
        $$iref{$$p{prefix}.'MaxT'}='+'.$$iref{$$p{prefix}.'MaxT'} if ($$iref{$$p{prefix}.'MaxT'}>0);
        $$iref{$$p{prefix}.'twater'}='+'.$$iref{$$p{prefix}.'twater'} if ($$iref{$$p{prefix}.'twater'}>0);
        
        $$iref{$$p{prefix}.'time'}=$$p{daystart}+$$p{hour}*3600;

    poltora, 11 Августа 2009

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

    +161

    1. 1
    2. 2
    if ($_GET['prot'] && !ereg("^[_a-zA-Z0-9]+$",$_GET['prot'])) 	$_GET['prot'] = "";
    if ($_GET['id']   && !ereg("^[_a-zA-Z0-9]+$",$_GET['id'])) 	$_GET['id'] = "";

    разбирал один скрипт и нашел там такую проверку
    это особенно весело смотрится, если учесть, что в этих переменных должно быть число

    dead_star, 11 Августа 2009

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