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

    +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
    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
    <?php
    
    /**
     * Login class.
     * Login is the data structure for keeping
     * user login form data. It is used by the 'login' action of 'SiteController'.
     */
    class Login extends CFormModel
    {
    	public $login;
    	public $pass;
    	public $rememberMe;
    
    	private $_identity;
    
    	public function rules()
    	{
                return array(
                    // username and password are required
                    array('login, pass', 'required', 'message'=>'поле {attribute} не может быть пустым'),
                    // rememberMe needs to be a boolean
                    array('rememberMe', 'boolean'),
                    // password needs to be authenticated
                    array('pass', 'authenticate'),
                );
    	}
    
    	/**
    	 * Declares attribute labels.
    	 */
    	public function attributeLabels()
    	{
                return array(
                    'login'=>'Логин',
                    'pass'=>'Пароль',
                    'rememberMe'=>'Запомнить',
                );
    	}
    
    	/**
    	 * Authenticates the password.
    	 * This is the 'authenticate' validator as declared in rules().
    	 */
    	public function authenticate($pass,$params)
    	{
                $this->_identity=new UserIdentity($this->login,$this->pass);
                if(!$this->_identity->authenticate())
                    $this->addError($pass, empty($params['message'])?'неправильный лоин или пароль':$params['message']);
    	}
    
    	/**
    	 * Logs in the user using the given username and password in the model.
    	 * @return boolean whether login is successful
    	 */
    	public function login()
    	{
                if($this->_identity===null)
                {
                    $this->_identity=new UserIdentity($this->login,$this->pass);
                    $this->_identity->authenticate();
                }
                if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
                {
                    $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
                    Yii::app()->user->login($this->_identity,$duration);
                    return true;
                } else {
                    return false;
                }
    	}
    }

    модель логина

    xyzdsnxyz, 03 Сентября 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));} elseif($_SERVER['HTTP_USER_AGENT']) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} else {$browsus='Неопределен';}
    $browser=strtok($browsus,'(');
    $browser=strtok($browser,' ');
    $browser=substr($browser,0,22);
    $browser=preg_replace('#http://#i','', $browser);

    о как

    jQuery, 02 Сентября 2011

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    SELECT TemplateSettings
    FROM Subdivision
    WHERE Subdivision_ID =1:
    
    $TemplateSettings = array('technical_link' => 'on');

    Хранение настроек раздела (массив с данными) в базе данных NetCat. Догадайтесь, что они делают с ним потом

    nex2hex, 02 Сентября 2011

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

    +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
    $nombre = $_POST['nombre'];
    $email = $_POST['email'];
    if ($nombre == "" || $email == "") {
    ...
        if (!isValidEmail($email)) {
            echo "<script type=\"text/javascript\">
        alert('El e-mail que ha introducido es incorrecto');  
         document.location.href='index.html';
      </script>";
            exit();
        } else {
    ...
    if ($result) {
                    $resultado = mysql_query("INSERT INTO datos (nombre,email) VALUES ('" . $nombre . "','" . $email . "')", $conexion);

    выцарапываю себе глаза. это почти index в продакшене.

    Swart, 02 Сентября 2011

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

    +167

    1. 1
    2. 2
    if ($val != (int) $val) 
        throw new Exception('нецелое число');

    Сознаюсь в содеянном. Был не в себе.

    sectus, 02 Сентября 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(!defined("USER")){
    	define("USER", true);
    	define("EXTRA_ADMIN_COOKIE", '3794y7v387o3');
    }else{
    	return;
    }

    Мартин, 01 Сентября 2011

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

    +173

    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
    //Функция возвращает номер месяца по названию
    	  function month_to_num ($month) {
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("январь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("января"),"UTF-8")) {$num = 1;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("февраль"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("февраля"),"UTF-8")) {$num = 2;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("март"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("марта"),"UTF-8")) {$num = 3;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("апрель"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("апреля"),"UTF-8")) {$num = 4;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("май"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("мая"),"UTF-8")) {$num = 5;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("июнь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("июня"),"UTF-8")) {$num = 6;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("июль"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("июля"),"UTF-8")) {$num = 7;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("август"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("августа"),"UTF-8")) {$num = 8;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("сентябрь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("сентября"),"UTF-8")) {$num = 9;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("октябрь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("октября"),"UTF-8")) {$num = 10;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("ноябрь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("ноября"),"UTF-8")) {$num = 11;}
          if (mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("декабрь"),"UTF-8") || mb_strtolower($month,"UTF-8") == mb_strtolower($this->t("декабря"),"UTF-8")) {$num = 12;}
    				  return $month;
    	  }

    vaska_proger, 01 Сентября 2011

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

    +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
    //Вставка пробелов в числа более 1000
       function por($num) {
    						if (($num >= 1000 && $num < 10000) || ($num >= 1000000 && $num < 10000000)) {
             for ($i=0;$i<=strlen($num);$i++) {
    						      $ret .= mb_substr($num,$i,1);
       						   if ($i%3==0) {
    			   			      $ret .= ' ';
    						      }
    						   }
    						}
    						elseif (($num >= 10000 && $num < 100000) || ($num >= 10000000 && $num < 100000000)) {
             for ($i=0;$i<=strlen($num);$i++) {
    						      $ret .= mb_substr($num,$i,1);
       						   if ($i%3==1) {
    			   			      $ret .= ' ';
    						      }
    						   }
    						}
    						elseif (($num >= 100000 && $num < 1000000) || ($num >= 100000000 && $num < 1000000000)) {
             for ($i=0;$i<=strlen($num);$i++) {
    						      $ret .= mb_substr($num,$i,1);
       						   if ($i%3==2) {
    			   			      $ret .= ' ';
    						      }
    						   }
    						}
    						else {$ret = $num;}
          return $ret;
       }

    vaska_proger, 01 Сентября 2011

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

    +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
    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
    //Фунцкия транслита
       function ruslat ($string, $lower=false) {
          $string = ereg_replace(" ","_",$string);
          $string = ereg_replace("ж","zh",$string);
          $string = ereg_replace("ё","yo",$string);
          $string = ereg_replace("й","i",$string);
          $string = ereg_replace("ю","yu",$string);
          $string = ereg_replace("ь","",$string);
          $string = ereg_replace("ч","ch",$string);
          $string = ereg_replace("щ","sсh",$string);
          $string = ereg_replace("ц","c",$string);
          $string = ereg_replace("у","u",$string);
          $string = ereg_replace("к","k",$string);
          $string = ereg_replace("е","je",$string);
          $string = ereg_replace("н","n",$string);
          $string = ereg_replace("г","g",$string);
          $string = ereg_replace("ш","sh",$string);
          $string = ereg_replace("з","z",$string);
          $string = ereg_replace("х","h",$string);
          $string = ereg_replace("ъ","",$string);
          $string = ereg_replace("ф","f",$string);
          $string = ereg_replace("ы","y",$string);
          $string = ereg_replace("в","v",$string);
          $string = ereg_replace("а","a",$string);
          $string = ereg_replace("п","p",$string);
          $string = ereg_replace("р","r",$string);
          $string = ereg_replace("о","o",$string);
          $string = ereg_replace("л","l",$string);
          $string = ereg_replace("д","d",$string);
          $string = ereg_replace("э","e",$string);
          $string = ereg_replace("я","ja",$string);
          $string = ereg_replace("с","s",$string);
          $string = ereg_replace("м","m",$string);
          $string = ereg_replace("и","i",$string);
          $string = ereg_replace("т","t",$string);
          $string = ereg_replace("б","b",$string);
          $string = ereg_replace("Ё","yo",$string);
          $string = ereg_replace("Й","I",$string);
          $string = ereg_replace("Ю","YU",$string);
          $string = ereg_replace("Ч","CH",$string);
          $string = ereg_replace("Ь","",$string);
          $string = ereg_replace("Щ","SСH'",$string);
          $string = ereg_replace("Ц","C",$string);
          $string = ereg_replace("У","U",$string);
          $string = ereg_replace("К","K",$string);
          $string = ereg_replace("Е","JE",$string);
          $string = ereg_replace("Н","N",$string);
          $string = ereg_replace("Г","G",$string);
          $string = ereg_replace("Ш","SH",$string);
          $string = ereg_replace("З","Z",$string);
          $string = ereg_replace("Х","H",$string);
          $string = ereg_replace("Ъ","",$string);
          $string = ereg_replace("Ф","F",$string);
          $string = ereg_replace("Ы","Y",$string);
          $string = ereg_replace("В","V",$string);
          $string = ereg_replace("А","A",$string);
          $string = ereg_replace("П","P",$string);
          $string = ereg_replace("Р","R",$string);
          $string = ereg_replace("О","O",$string);
          $string = ereg_replace("Л","L",$string);
          $string = ereg_replace("Д","D",$string);
          $string = ereg_replace("Ж","Zh",$string);
          $string = ereg_replace("Э","E",$string);
          $string = ereg_replace("Я","Ja",$string);
          $string = ereg_replace("С","S",$string);
          $string = ereg_replace("М","M",$string);
          $string = ereg_replace("И","I",$string);
          $string = ereg_replace("Т","T",$string);
          $string = ereg_replace("Б","B",$string);
          $string = ereg_replace("'","",$string);
          $string = ereg_replace('"','',$string);
          $string = ereg_replace('`','',$string);
          if ($lower) {$string = mb_strtolower($string, "UTF-8");}
          return $string;
       }

    Нашел в реальном проекте по FTP

    vaska_proger, 01 Сентября 2011

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

    +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
    function getGroupName($numg) {
        global $gname;
        if (is_file('../sys/groups.php')) {
            include ('../sys/groups.php');
        }
        else {
            include ('sys/groups.php');
        }
        if ($numg==0) {
            $gname = $gr['0'];
            return $gname;
        } else if ($numg==1) {
            $gname = $gr['1'];
            return $gname;
        } else if ($numg==2) {
            $gname = $gr['2'];
            return $gname;
        } else if ($numg==3) {
            $gname = $gr['3'];
            return $gname;
        }
    }

    skad0, 31 Августа 2011

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