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

    +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
    function key_exists_check($key,$ar)
    {
            if (empty($key))
                    $key = '0.001';
    
            strval($key);
    
            if (array_key_exists($key,$ar))
                    while (array_key_exists($key,$ar))
                            $key=strval(floatval($key)+0.001);
    
            return strval($key);
    }

    Другого решения не вижу - задача при добавлении в массив - делать уникальные ключи, которые типа float.

    atarix12, 12 Мая 2010

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

    +167

    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
    abstract class DataBaseConnection {
      static public  $user   = "root";
      static private $pass   = "";
      static private $host   = "localhost";
      static private $dbName = "example";
    
      //this method creates connection to server and selects data base    
      static public function dbConnect () {
            //initialize connection variables 
            $host   = self :: $host;
            $dbName = self :: $dbName;
            $pass   = self :: $pass;
            $user   = self :: $user;
            // connect to server
            $connection = mysql_connect ( $host, $user, $pass, TRUE ) or die ("DATA BASE CONNECTION FAIL : " . mysql_error());
            // select database
            mysql_select_db ( $dbName, $connection ) or die ("DATA BASE HAS NOT BEEN SELECT");
            //set query encoding
            mysql_query("set names utf8") or die("set names utf8 failed") ;  
            
            return $connection;
      }
    }
    
    DataBaseConnection :: $user = "root";
     
    $connection = DataBaseConnection :: dbConnect ();

    kkkoi8r, 08 Мая 2010

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

    +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
    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
    //--------------- Функция подсчета карт в игре ---------------//
    function cards_score($str){
    if($str==1||$str==2||$str==3||$str==4){
    $num = 6;
    }
    if($str==5||$str==6||$str==7||$str==8){
    $num = 7;
    }
    if($str==9||$str==10||$str==11||$str==12){
    $num = 8;
    }                
    if($str==13||$str==14||$str==15||$str==16){
    $num = 9;
    }                
    if($str==17||$str==18||$str==19||$str==20){
    $num = 10;
    }                
    if($str==21||$str==22||$str==23||$str==24){
    $num = 2;
    }                
    if($str==25||$str==26||$str==27||$str==28){
    $num = 3;
    }                      
    if($str==29||$str==30||$str==31||$str==32){
    $num = 4;
    }                      
    if($str==33||$str==34||$str==35||$str==36){
    $num = 11;
    }                      
    return $num;
    }
    
    
    //--------------- Функция подсчета очков в игре ---------------//
    function cards_points($str){
    $str=(int)$str;    
    $points = ' очков';
    if($str==2||$str==3||$str==4||$str==22||$str==23||$str==24|$str==32||$str==33||$str==34){$points = ' очка';}
    if($str==21){$points = ' <b>очко!!!</b>';}
    if($str==31){$points = ' очко';}
    return $str.$points;
    } 
    
    //--------------- Функция вывода статуса ---------------//
    function user_ststuses($balls) {
    
    $text = file_get_contents(DATADIR."status.dat"); 
    if ($text!=""){
    $udta = explode("|",$text);}
    if($balls>=0 && $balls<5){$statuses=$udta[0];}
    if($balls>=5 && $balls<10){$statuses=$udta[1];}    
    if($balls>=10 && $balls<20){$statuses=$udta[2];}
    if($balls>=20 && $balls<50){$statuses=$udta[3];}
    if($balls>=50 && $balls<100){$statuses=$udta[4];}
    if($balls>=100 && $balls<250){$statuses=$udta[5];}    
    if($balls>=250 && $balls<500){$statuses=$udta[6];}
    if($balls>=500 && $balls<750){$statuses=$udta[7];}
    if($balls>=750 && $balls<1000){$statuses=$udta[8];}
    if($balls>=1000 && $balls<1250){$statuses=$udta[9];}
    if($balls>=1250 && $balls<1500){$statuses=$udta[10];}
    if($balls>=1500 && $balls<1750){$statuses=$udta[11];}
    if($balls>=1750 && $balls<2000){$statuses=$udta[12];}
    if($balls>=2000 && $balls<2250){$statuses=$udta[13];}
    if($balls>=2250 && $balls<2500){$statuses=$udta[14];}
    if($balls>=2500 && $balls<2750){$statuses=$udta[15];}
    if($balls>=2750 && $balls<3000){$statuses=$udta[16];}
    if($balls>=3000 && $balls<3250){$statuses=$udta[17];}
    if($balls>=3250 && $balls<3499){$statuses=$udta[18];}
    if($balls>=3500 && $balls<4999){$statuses=$udta[19];}
    if($balls>=5000 && $balls<7499){$statuses=$udta[20];}
    if($balls>=7500 && $balls<9999){$statuses=$udta[21];}
    if($balls>=10000){$statuses=$udta[22];}
    $statuses=check($statuses);
    
    return $statuses;
    }

    3 сорца отсюда http://visavi.net/load/zip.php?act=preview&id=988&view=854&star t=840&

    This is obvious, 07 Мая 2010

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

    +144

    1. 1
    $x ^= $y ^= $x ^= $y

    как это выражение меняет местами значения Х и Y ?
    или что за оператор такой ^= ?

    Phoenix123, 07 Мая 2010

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

    +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
    <?php
    include ("config.php");
    include ("css/css.inc.php");
    include ("inc/audioplayer.inc.php");
    
    // Определяем текущий раздел.
    
    $CurSec=empty($_GET['section'])?null:$_GET['section'];
    
        // Если после "?section=" ничего нет, то грузим файл по умолчанию,
        // а именно "index.inc.php" из папки "sections".
    
        if(empty($CurSec))
        include("./sections/index.inc.php");
    
        // Если "?section=MyHouse" и файл "MyHouse.inc.php" в папке "sections" существует,
        // то подгружаем его.
    
        elseif(file_exists("./sections/".basename($CurSec).".inc.php"))
        include("./sections/".basename($CurSec).".inc.php");
    
        // Если "?section=MyHouse" и файл "MyHouse.inc.php" в папке "sections" НЕ существует,
        // то подгружаем "error.inc.php" всё из той же папки "sections".
    
        else
        include("./sections/error.inc.php");
    
    print "$body";
    
    ?>

    sergylens, 07 Мая 2010

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

    +159

    1. 1
    2. 2
    3. 3
    $datex = date("Y-m");
    $tr = explode("-",$datex);
    $ddr = $tr[0]."-".$tr[1];

    Небось такое уже было

    Werdn, 07 Мая 2010

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // пример 1
    a) $query = "SELECT id,text_name,textarea_desc,img_photo,date_reg FROM {$prefix2}_{$module} WHERE id='$id' AND check_active=1 ORDER BY $order LIMIT $limit";
    или же
    b) $query = "SELECT id,text_name,textarea_desc,img_photo,date_reg FROM ".$prefix2."_".$module." WHERE id='".$id."' AND check_active=1 ORDER BY ".$order." LIMIT ".$limit;
    
    // пример 2
    c) $query = "INSERT INTO {$prefix2}_{$module} SET text_name='$name',date_add=NOW(),text_fio='$fio' WHERE id='$id'";
    или же
    d) $query = "INSERT INTO ".$prefix2."_".$module." SET text_name='".$name."',date_add=NOW(),text_fio='".$fio."' WHERE id='".$id."'";

    Как-то некий посетитель этого сайта назвал a и с -- говнокодом. Интересно узнать Ваше мнение по этому поводу.
    Желательно услышать хоть какую-то аргументацию, вместо пресловутых трольских комментов ))
    Все переменные перед использованием естественно приведены к безопастному виду.
    Ни о каких инъекций речь просьба не поднимать...

    Death, 07 Мая 2010

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

    +121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $InsetInTable="INSERT INTO Clients (ID, kodRDPO, FIO, telefon, fax, email, kodPDV, svidoctvo, Date)
    VALUES ('$num', '$drpo_d', '$name_d','$telefon_d','$fax_d','$e_mail_d','$pdv_d','$svidoctvo_d','$today')";
    
    mysql_query($InsetInTable,$dbcnx);
    if (!mysql_query($InsetInTable,$dbcnx)){
    	   echo("<P>В настоящий момент сервер базы данных не доступен, поэтому 
               корректное создание новой записи в таблицу не возможно.</P>");
           echo ("<p><b>Error: ".mysql_error()."</b><p>");
           exit();
    	}
    	
    mysql_close($dbcnx);

    Проверка на правельность записи

    Vasiliy, 07 Мая 2010

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

    +149

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if ($entry=='') {
     $entry = 0;
    }
    
    .......................
    
    $comment = nl2br($row['comment']);
    $comment = emotion($comment);
    $comment = links($comment);
    $comment = $comment.'<br> написал'.$user;

    Servantes, 07 Мая 2010

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

    +162

    1. 1
    $file=@implode("",file("http://www.google.com/search?&;q=site:$url&hl=en"));

    Крутой аналог file_get_contents.

    mr.The, 06 Мая 2010

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