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

    +189

    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
    function location ($url)
    { // Перенаправление:
    	@ header ("Location: $url");
    	echo "<html>\n";
    	echo "<head>\n";
    	echo "<meta http-equiv='refresh' content='0; url=$url' />\n";
    	echo "<title>$url</title>\n";
    	echo "<script type='text/javascript'>//<![CDATA[\n";
    	echo "document.location = '$url';\n";
    	echo "//]]></script>\n";
    	echo "</head>\n";
    	echo "<body>\n";
    	echo "<a href='$url'>Click me</a>\n";
    	echo "</body>\n";
    	echo "</html>";
    	kernel_exit();
    }

    Перенаправление (кроссбраузерное).

    Arigato, 13 Октября 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function is_ints($s)
    {
      $s:=$s[0]+0;
      if(gettype($s)=="integer"){return true}else{return false}
    }

    Из моей молодости.. Проверка является ли строка числом.. Даже стыдно :)

    sera, 12 Октября 2010

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

    +159

    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
    // Функция для подключения к БД
    
    // *** параметры коннекта ***
    ErrorsOff();
    $this->DbAccess = @mysql_connect($this->Server, $this->User, $this->Password);
    ErrorsOn();
    if($this->DbAccess){
    	$this->Connected = true;
    	@mysql_query("set character_set_client='cp1251'");
    	@mysql_query("set character_set_results='cp1251'");
    	@mysql_query("set collation_connection='cp1251_general_ci'");
    	$this->Version = mysql_get_server_info();
    	if($dbname != "" && @mysql_select_db($dbname, $this->DbAccess)){
    		// *** отмечаем текущую базу ***
    	}
    }else{
    	$this->Error('Не удалось подключиться к серверу!');
    	$this->MySQLError();
    	return false;
    }
    $this->Good();
    return true;

    Мартин, 12 Октября 2010

    Комментарии (15)
  4. Python / Говнокод #4357

    −181

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    def get_children(self, **kwargs):
        q = super(Classifier, self).get_children()
        try:           
            for i in kwargs['related']:
                q = q.filter(classifiers = super(Classifier, self).get_by(i, key='translit'))
        except:
            pass
        return q

    такое в django проекте

    t0ster, 12 Октября 2010

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

    +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
    <?
    // регистрационная информация (пароль #1)
    // registration info (password #1)
    $mrh_pass1 = "Morbid11";
    
    // чтение параметров
    // read parameters
    $out_summ = $_REQUEST["OutSum"];
    $inv_id = $_REQUEST["InvId"];
    $shp_item = $_REQUEST["Shp_item"];
    $crc = $_REQUEST["SignatureValue"];
    
    $crc = strtoupper($crc);
    
    $my_crc = strtoupper(md5("$out_summ:$inv_id:$mrh_pass1:Shp_item=$shp_item"));
    
    // проверка корректности подписи
    // check signature
    if ($my_crc != $crc)
    {
      echo "bad sign\n";
      exit();
    }
    
    // проверка наличия номера счета в истории операций
    // check of number of the order info in history of operations
    $f=@fopen("order.txt","r+") or die("error");
    
    while(!feof($f))
    {
      $str=fgets($f);
    
      $str_exp = explode(";", $str);
      if ($str_exp[0]=="order_num :$inv_id")
      { 
    	echo "Операция прошла успешно\n";
    	echo "Operation of payment is successfully completed\n";
      }
    }
    fclose($f);
    ?>

    учитесь, как надо с онлайн-наличкой работать
    http://www.robokassa.ru/Doc/demo_php.zip

    xXx_totalwar, 12 Октября 2010

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

    +175

    1. 1
    2. 2
    3. 3
    4. 4
    function safe($s) // Против SQL-иньекций
    {
    	return $s;
    }

    IlyaBarkov, 12 Октября 2010

    Комментарии (13)
  7. Java / Говнокод #4354

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    List<String> el=parseList();
    		Theme th=new Theme(id);
    
    		th.setScore=Integer.parseInt(el.get(1));
    		th.setComments=Integer.parseInt(el.get(2));
    		th.setAuthor=el.get(3);
    		th.setVisitors=Integer.parseInt(el.get(4));
    		th.setVisitorsLastWeek=Integer.parseInt(el.get(5));
    		th.eMail=el.get(5);
    		return th;

    3.14159265, 12 Октября 2010

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

    +165

    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
    function FormatCurrency($fSum, $strCurrency)
    {
    	return CurrencyFormat($fSum, $strCurrency);
    	/*
    	if (!isset($fSum) || strlen($fSum)<=0) return "";
    
    	$arCurFormat = CCurrencyLang::GetCurrencyFormat($strCurrency);
    
    	if (!isset($arCurFormat["DECIMALS"])) $arCurFormat["DECIMALS"] = 2;
    	$arCurFormat["DECIMALS"] = IntVal($arCurFormat["DECIMALS"]);
    	if (!isset($arCurFormat["DEC_POINT"])) $arCurFormat["DEC_POINT"] = ".";
    	if (!isset($arCurFormat["THOUSANDS_SEP"])) $arCurFormat["THOUSANDS_SEP"] = "\\"."xA0";
    	$tmpTHOUSANDS_SEP = $arCurFormat["THOUSANDS_SEP"];
    	eval("\$tmpTHOUSANDS_SEP = \"$tmpTHOUSANDS_SEP\";");
    	$arCurFormat["THOUSANDS_SEP"] = $tmpTHOUSANDS_SEP;
    	if (!isset($arCurFormat["FORMAT_STRING"])) $arCurFormat["FORMAT_STRING"] = "#";
    
    	$num = number_format($fSum, $arCurFormat["DECIMALS"], $arCurFormat["DEC_POINT"], $arCurFormat["THOUSANDS_SEP"]);
    
    	return str_replace("#", $num, $arCurFormat["FORMAT_STRING"]);
    	*/
    }

    1C-Bitrix,
    /bitrix/modules/catalog/include.php

    Under, 12 Октября 2010

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

    +144

    1. 1
    datagridview.CurrentRow.Index = datagridview.CurrentRow.Index + 1;

    Как можно использовать данный код?
    Ошибка: Property or indexer 'System.Windows.Forms.DataGridViewBand.I ndex' cannot be assigned to -- it is read only

    daffsik, 12 Октября 2010

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

    +149

    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
    error_reporting(1);
    require("sells_pages.php");   // ЗДЕСЬ включен массив в виде 'бла-бла ссылка' => 'ее урл',
    
    $max_links = count($sells_pages); //Считает все элементы массива со ссылками
    $random_link_number = rand(0,$max_links); //Выбирает номер случайной строки массива
    
    $link = array_chunk($sells_pages, 1); //Разбивает массив по одному урлу
    
    for($i=0;$i<$max_links;$i++) { 
    	//echo $i." - ".$link[$i][0]."<br>"; //Присваивает переменной $i значение каждой ссылки
    	if ($random_link_number == $i) { $t_link = $link[$i][0]; }  //Сопоставляет случайное значение элементу массива  
    }
    
    //echo "<b>".$today_link."</b>";
    
    if (in_array($t_link, $sells_pages)) { //Проверяет наличие урла в исходном массиве и добавляет анкор
    	$title = array_keys($sells_pages, $t_link);
    	$today_link = "<a href='http://stopfire.ru/$t_link'>$title[0]</a>"; //Формирует конечную ссылку 
    }
    
    $current_address = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; //Сопоставляет адреса чтобы не ссылать страницу на саму себя 
    if ($current_address != $today_link) {
    echo $today_link."<br>";
    }

    спрашивается зачем сравнивать со значением rand когда есть функция array_rand ?
    Гораздо проще так:
    $rand_keys = array_rand($sells_pages, 2);
    echo $sells_pages[$rand_keys[0]] . "\n";
    Понял через два часа))

    alex-engine, 12 Октября 2010

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