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

    +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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    <?php
     if (isset($_POST['update'])) {
    			 $kolcen=mysql_real_escape_string($_POST['kolcen']);
    			 $tovar=mysql_real_escape_string($_POST['tovar']);
    			 $descr=mysql_real_escape_string($_POST['descr']);
    			 $price=intval($_POST['price']);
    			 $price2=intval($_POST['price2']);
    			 $price3=intval($_POST['price3']);
    			 $id=intval($_POST['update']); 
    			 $zag1=mysql_real_escape_string($_POST['zag1']);
    			 $zag2=mysql_real_escape_string($_POST['zag2']);
    			 $zag3=mysql_real_escape_string($_POST['zag3']);
    			 
    			  switch($kolcen){ 
    		 case '3':$updatetovar = mysql_query ("UPDATE `tovar3` SET `tovar`='$tovar',`descr`='$descr',`price`='$price',`price2`='$price2',`price3`='$price3' WHERE `id`='$id' and `id`='$serv'");
    		 break; 
    		 case '2': $updatetovar = mysql_query ("UPDATE `tovar2` SET `tovar`='$tovar',`descr`='$descr',`price`='$price',`price2`='$price2' WHERE `id`='$id' and `id`='$serv'");
    		 break; 
    		 case '1':$updatetovar = mysql_query ("UPDATE `tovar` SET `tovar`='$tovar',`descr`='$descr',`price`='$price' WHERE `id`='$id' and `pizzaid`='$service'");
    		 break;
    		 case '2images': $updatetovar = mysql_query ("UPDATE `2images` SET `tovar`='$tovar',`descr`='$descr',`price`='$price',`price2`='$price2',`price3`='$price3',`img`='$img',`zag1`='$zag1',`zag2`='$zag2',`zag3`='$zag3' WHERE `id`='$id' and `id`='$serv'");
    		 break;
    		 }
    ?>

    Народ зацените мой код плиз на предмет говнокода, и если чето не так то дайте совет . Этот код для админки добавления товаров. Есть 4 типа категорий, товар с одной ценой, с двумя, с тремя, и товар с двумя картинками. В зависимости от типа категории делаем запрос к базе

    frie, 21 Июня 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    protected function readConfig($configPath) {
        $ini = parse_ini_file($configPath);
        foreach ($ini as $key => $value) {
            $config[$key] = $value;
        }
        return $config;
    }

    xarper, 21 Июня 2011

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

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $black = "eval|file_get_contents|mysql_(.*?)|include|require|readfile|show_source|highlight|import_request_variables|extract|parse_str|assert|passthru|exec|system|shell_exec|proc_open|fopen|echo";
    
    if(preg_match("#\<\?(.*?)($black)(.*?)\?\>#i", $template)){
    exit ("1");
    break;
    }

    substr, 20 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    if ($a = 1) {
    	...бла-бла-бла
    }

    nislova, 20 Июня 2011

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

    +156

    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
    <?php 
    	if(isset($_GET["status"])) {
    		//Определяем переменные
    		$user_id = $_GET['user_id'];
    		$operator_id = $_GET['operator_id'];
    		$smsid = $_GET['smsid'];
    		$operator_id_str = $_GET['operator_id_str'];
    		$num = $_GET['num'];
    		$msg_trans = $_GET['msg_trans'];
    		$msg = $_GET['msg'];
    		$cost_rur = $_GET['cost_rur'];
    		$ratepoints = $cost_rur; //Рейтинг = стоимость смс
    		
    		//Подключаемся к бд
    		$dblocation = "localhost";	 // Имя сервера
    		$dbuser = "****";          // Имя пользователя
    		$dbpasswd = "******";            // Пароль
    		$dbname = "******"; //Имя бд
    		$dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);
    		if (!$dbcnx) {
    			  echo("Не удалось установить соеденение");
    			  exit();
    		} else  {
    						if (!@mysql_select_db($dbname, $dbcnx)) {
    							  echo  "База данных недоступна <br />" ;
    							  exit();
    						} else {
    							//Проверяем зарегестрирован ли пользователь
    							$changeuser = @mysql_query("SELECT * FROM jos_users WHERE  username='$user_id'");
    							if(@mysql_num_rows($changeuser) > 0) {
    							//Пользователь зарегестрирован
    								@mysql_query("INSERT INTO sms (operator_id, operator_id_str, user_id, smsid, num, msg_trans, msg, cost_rur) VALUES ('$operator_id','$operator_id_str','$user_id','$smsid','$num','$msg_trans','$msg','$cost_rur')"); //Добавляем смс
    								@mysql_query("UPDATE jos_users SET rate = rate +1 WHERE username='$user_id'"); //Увеличиваем рейтинг
    								@mysql_query("UPDATE jos_users SET sms = sms +1 WHERE username='$user_id'"); //Увеличиваем кол-во смс
    								$rate = @mysql_fetch_array(@mysql_query("SELECT rate FROM jos_users WHERE username='$user_id'"));
    								echo "SMS Send OK rate +1 your rate: ".$rate['rate']."";
    							} else {
    							/*Пользователь не зарегестрирован,
    							Регестрируем пользователя*/
    							$regdate = date("Y-m-d  H:i:s");
    							
    							//Генерируем пароль
    							$pass = rand(10000, 99999);
    							$sqlpass = md5($pass);
    							
    							//Добавляем пользователя
    								@mysql_query("INSERT INTO jos_users (name, username, password, usertype, gid, registerDate, lastvisitDate) VALUES ('$user_id', '$user_id', '$sqlpass', 'Registered', '18', '$regdate', '$regdate')");
    								$getnewuserid = @mysql_fetch_array(@mysql_query("SELECT id FROM jos_users WHERE username='$user_id'"));
    								@mysql_query("INSERT INTO jos_core_acl_aro (section_value, value, order_value, name, hidden) VALUES ('users', '{$getnewuserid['id']}', '0', '$user_id', '0')");
    								$getaro_id = @mysql_fetch_array(@mysql_query("SELECT id FROM jos_core_acl_aro WHERE name='$user_id'"));
    								@mysql_query("INSERT INTO jos_core_acl_groups_aro_map (group_id, aro_id) VALUES ('18', '{$getaro_id['id']}')");
    								
    								@mysql_query("INSERT INTO sms (operator_id, operator_id_str, user_id, smsid, num, msg_trans, msg, cost_rur) VALUES ('$operator_id','$operator_id_str','$user_id','$smsid','$num','$msg_trans','$msg','$cost_rur')"); 
    								@mysql_query("UPDATE jos_users SET rate = rate +1 WHERE username='$user_id'");
    								@mysql_query("UPDATE jos_users SET sms = sms +1 WHERE username='$user_id'");
    								$rate = @mysql_fetch_array(@mysql_query("SELECT rate FROM jos_users WHERE username='$user_id'"));
    								echo "SMS Register complete. Login: ".$user_id." Pass: ".$pass." Your rate: ".$rate['rate']."";
    							}
    									}
    			}
    	}
    ?>

    phplamer, 20 Июня 2011

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

    +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
    function retPercByAct($num,$economy) { //50% discount => economy=0 => 15%
      $t='15/5 0-49,
      16/6 50-100,
      17/7 101-200,
      18/8 201-350,
      19/9 351-500,
      20/10 601-1000,
      21/11 1001-500000,';
      $t=explode(',',$t);
      foreach($t as $k=>$v) {
        $v=trim($v);
        list($perc,$nums)=explode(' ',$v);
        $nums=explode('-',$nums);
        if($nums[0]<=$num && $nums[1]>=$num) {
          $perc=explode('/',$perc);
          if(!$economy) $percR=$perc[0]; else $percR=$perc[1];
          break;
        }
      }
      return $percR;
    }

    Вот, встретилось в поддерживаемом мной проекте.

    segoddnja, 20 Июня 2011

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

    +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
    $a=array(
    		'save'=>array(
    			'state'=>array('new'=>array(1, 1), 0=>array(0, 0), 1=>array(1, 1), 3=>array(1, 1), 4=>array(0, 0), 5=>array(0, 0), 6=>array(1, 1)),
    			'dest'=>1,
    		),
    		'save_and_back'=>array(
    			'state'=>array('new'=>array(1, 1), 0=>array(0, 0), 1=>array(1, 1), 3=>array(1, 1), 4=>array(0, 0), 5=>array(0, 0), 6=>array(1, 1)),
    			'dest'=>1,
    		),
    		'save_as_a_copy'=>array(
    			'state'=>array('new'=>array(0, 0), 0=>array(1, 1), 1=>array(1, 1), 3=>array(1, 1), 4=>array(1, 1), 5=>array(1, 1), 6=>array(1, 1)),
    			'dest'=>1,
    		),
    		'resend'=>array(
    			'state'=>array('new'=>array(0, 0), 0=>array(1, 1), 1=>array(1, 1), 3=>array(1, 1), 4=>array(1, 1), 5=>array(1, 1), 6=>array(1, 1)),
    			'dest'=>1,
    		),
    		'send'=>array(
    			'state'=>array('new'=>array(0, 1), 0=>array(0, 0), 1=>array(0, 1), 3=>array(0, 1), 4=>array(0, 0), 5=>array(0, 1), 6=>array(0, 1)),
    			'dest'=>array(1,3),
    		),
    		'testsend'=>array(
    			'state'=>array('new'=>array(0, 1), 0=>array(0, 0), 1=>array(0, 1), 3=>array(0, 1), 4=>array(0, 0), 5=>array(0, 1), 6=>array(0, 1)),
    			'dest'=>array(1,3),
    		),
    		'offer'=>array(
    			'state'=>array('new'=>array(1, 0), 0=>array(0, 0), 1=>array(1, 0), 3=>array(0, 0), 4=>array(0, 0), 5=>array(0, 0), 6=>array(1, 0)),
    			'dest'=>5,
    		),
    		'reject'=>array(
    			'state'=>array('new'=>array(0, 0), 0=>array(0, 0), 1=>array(0, 0), 3=>array(0, 0), 4=>array(0, 0), 5=>array(0, 1), 6=>array(0, 0)),
    			'dest'=>6,
    		),
    		'cancel'=>array(
    			'state'=>array('new'=>array(0, 0), 0=>array(0, 0), 1=>array(1, 1), 3=>array(0, 0), 4=>array(0, 0), 5=>array(0, 0), 6=>array(0, 0)),
    			'dest'=>1,
    		),
    	);

    Без комментариев.

    pro_co_ru, 20 Июня 2011

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

    +160

    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
    public function getList($sort) {
            if ($sort == 'id')
                $select = $this->select()->order('id ASC');            
            if ($sort == 'id2')
                $select = $this->select()->order('id DESC');
            if ($sort == 'username')
                $select = $this->select()->order('username ASC');
            if ($sort == 'username2')
                $select = $this->select()->order('username DESC');
            if ($sort == 'firstname')
                $select = $this->select()->order('firstname ASC');
            if ($sort == 'firstname2')
                $select = $this->select()->order('firstname DESC');
            if ($sort == 'lastname')
                $select = $this->select()->order('lastname ASC');
            if ($sort == 'lastname2')
                $select = $this->select()->order('lastname DESC');
            if ($sort == 'lastdate')
                $select = $this->select()->order('lastdate ASC');
            if ($sort == 'lastdate2')
                $select = $this->select()->order('lastdate DESC');
            if ($sort == 'regdate')
                $select = $this->select()->order('regdate ASC');
            if ($sort == 'regdate2')
                $select = $this->select()->order('regdate DESC');
            if ($sort == 'city')
                $select = $this->select()->order('city ASC');
            if ($sort == 'city2')
                $select = $this->select()->order('city DESC');
            if ($sort == 'vote')
                $select = $this->select()->order('vote ASC');
            if ($sort == 'vote2')
                $select = $this->select()->order('vote DESC');
            $result = $this->fetchAll($select);
            return $result;
        }

    Кусочек кода, написанный в классической манере "if-else" для Zend Framework

    coderov, 20 Июня 2011

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

    +155

    1. 1
    2. 2
    3. 3
    $pageController = new PageController();
    $photo = $pageController->getPhoto($pageRecord->id);
    $photo =  $photo ;

    А вдруг ПХП с первого раза не понял что в переменной должно быть фото? Повторение мать учения.

    Kos, 19 Июня 2011

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

    +176

    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
    /**
        * получить перечень экзаменов на указанную дату
        * @global GathererDB $db
        * @param string $examdate must be $db->qstr()'ed
        * @return array 
        */
       function examsOnDate($examdate)
       {
         global $db;
         ob_start();
     ?>
    select distinct e.EXAMID from EXAMS e
    inner join STATIONEXAMS se on se.EXAMFK=e.SYS_GUID
    inner join PARTICIPANTSEXAMS pe on pe.EXAMFK=e.SYS_GUID
    where e.EXAMDATE=<?php print $examdate; ?>
    <?php
         $sql = ob_get_clean();
    
         $exams = $db->getcol($sql);
         return $exams;
       }

    Из скрипта для обслуживания сайта ЕГЭ.
    Изумительное применение буфера.

    7ion, 18 Июня 2011

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