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

    +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
    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
    <?php
    class security extends engine{
        var $temp=array();
    
        function getUserId(){
            $hash=explode('::',$_COOKIE['site_hash']);
            $id=$hash[0];
            return $id;
        }
    
        function getUserSecurityAccess($id){
            if(is_numeric($id)){
                $id=rawurlencode($id);
                $conn_id=mysql_connect('host','user','passwd');
                mysql_select_db('database');
                $q=mysql_query("SELECT groupid FROM `users`
                                WHERE id='".$id."'",$conn_id);
                if($q){
                    if(mysql_numrows($q)!=0){
                        $result=@mysql_fetch_assoc($q);
                        return $result['group_id'];
                    }else{
                        return -1;
                    }
                }else{
                    return -1;
                }
                mysql_close($conn_id);
            }else{
                return -1;
            }
        }
    
        function checkUserPermission($module,$act){
            #return true;
            $this->temp=array();
            $this->temp['_result']=0;
            $this->temp['_uid']=explode('::',$_COOKIE['site_hash']);
            $this->temp['_uid']=$this->temp['_uid'][0];
            $this->temp['_gid']=$this->getUserSecurityAccess($this->temp['_uid']);
            $this->temp['_conn_id']=mysql_connect('host','user','passwd');
            mysql_select_db('database');
            $this->temp['_q1']=mysql_query('SELECT perms'
                            .'FROM `secure_groups`' 
                            .'WHERE id='.$this->temp['_gid']);    
            $this->temp['_access_stamp']=mysql_fetch_assoc($this->temp['_q1']);
            $this->temp['_access_stamp']=$this->temp['_access_stamp']['perms'];
            $this->temp['_access_stamp']=explode(';',$this->temp['_access_stamp']);
            $this->temp['_access_stamp']=array_slice($this->temp['_access_stamp'],0,-1);
            foreach($this->temp['_access_stamp'] as $this->temp['v']){
                $this->temp['_mod_access']=explode(':',$this->temp['v']);
                $this->temp['_mod_indefier']=$this->temp['_mod_access'][0];
                if($this->temp['_mod_indefier']==$module){
                    $this->temp['_perms']=explode(',',$this->temp['_mod_access'][1]);
                    switch($act){
                        case 'r':
                            $this->temp['_result']=($this->temp['_perms'][0]==1)? 1:0;
                            break;
                        case 'w':
                            $this->temp['_result']=($this->temp['_perms'][1]==1)? 1:0;
                            break;
                    }
                    break;
                }
            }
            mysql_close($conn_id);
            return $this->temp['_result'];
        }
    }
    ?>

    Понравилось окончание статьи
    "Надеюсь, что мы скоро встретимся...
    Кто хочет почитать остальные мои статьи - прошу на http://e-code.tnt43.com.
    С уважением Карпенко Кирилл, глава IT-отдела ИНПП. "

    MoLe-X, 12 Марта 2011

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

    +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
    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
    <?php
    session_start();
    DEFINE('trusteko', true);
    @$l=$_GET['l'];
    //echo md5('12345');
    include_once "../admin/meta.php";
    include_once ("../inc/setup.php");
    include_once ("../inc/config.php");
    $dbc=db_connect();
    if(isset($_POST['reg']))
    {
    $query="SELECT * FROM `access` WHERE login='".$_POST['login']."' LIMIT 1";
    $result = mysql_query($query,$dbc);
    $row=mysql_fetch_array($result);
        if (md5($_POST['passwd'])==$row['parol'] and $_POST['login']==$row['login'])
        {
        $_SESSION['passwd']=$_POST['passwd'];
        $_SESSION['login']=$_POST['login'];
        //////////////////
    include "menu_text.php";
    	//////////////////
    	}
            else
            {
            echo "<center><form action=\"\" method=\"post\" name=\"reg\">
    <table style=\"width:400px; height:50px;border:1px;\" align=\"center\">
    <tr><td colspan=\"2\" style=\"text-align:center\">Авторизация</td></tr>
    <tr><td>Login:</td><td><input type=\"text\" name=\"login\"></td></tr>
    <tr><td>Password:</td><td><input type=\"password\" name=\"passwd\"></td></tr>
    <tr><Td colspan=\"2\"><input type=\"submit\" name=\"reg\" value=\"Вход\"></td></tr>
    </table>
    </form></center>";
            }
    }
    if (isset($_SESSION['login']) and !isset($_POST['reg']))
    {
        $query="SELECT * FROM `access` WHERE login='".$_SESSION['login']."' LIMIT 1";
        $result = mysql_query($query,$dbc);
        $row=mysql_fetch_array($result);
        if (md5($_SESSION['passwd'])==$row['parol'] and $_SESSION['login']==$row['login'])
        {
    		
        //////////////////
    include "menu_text.php";
    	//////////////////
    	}
    }
    
    if (!isset($_SESSION['login']) and !isset($_POST['reg']))
    {
    echo "<center><form action=\"\" method=\"post\" name=\"reg\">
    <table style=\"width:400px; height:50px;border:1px;\" align=\"center\">
    <tr><td colspan=\"2\" style=\"text-align:center\">Авторизация</td></tr>
    <tr><td>Login:</td><td><input type=\"text\" name=\"login\"></td></tr>
    <tr><td>Password:</td><td><input type=\"password\" name=\"passwd\"></td></tr>
    <tr><Td colspan=\"2\"><input type=\"submit\" name=\"reg\" value=\"Вход\"></td></tr>
    </table>
    </form></center>";
    }
    ?>

    Мое, этому коду 2 года )
    Веселая система авторизации.
    Разумеется я так уже не пишу ;)

    topilnik, 12 Марта 2011

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

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $i=10000;
    
    while(true)
    {
    $i--;
    
    if ($i==0) break;
    
    // Какойто код с $i
    }

    Выкопал в одном серьезном проекте. Так там что не цикл так while(true) c точками выхода по телу цикла..

    Vasiliy, 12 Марта 2011

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

    +166

    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
    <?php
      if (!isset($_REQUEST['page'])&&!isset($_REQUEST['story']))
      {
        header('Location: index.php');
        exit;
      }
    
      $page = $_REQUEST['page'];
      $story = intval($_REQUEST['story']);
    
      include_once('db_fns.php');
      include_once('header.php');
    
      $handle = db_connect();
      if($story)
      {
        $query = "select * from stories 
                  where id = '$story' and
                        published is not null";
      }
      else
      {
        $query = "select * from stories 
                  where page = '$page' and
                        published is not null
                  order by published desc";
      }
      $result = $handle->query($query);
    
      while ($story = $result->fetch_assoc()) 
      {
        // headline
        echo "<h2>{$story['headline']}</h2>";
        //picture
        if ($story['picture']) 
        {
          echo '<div style="float:right; margin:0px 0px 6px 6px;">';
          echo '<img src="resize_image.php?image=';
          echo urlencode($story[picture]);
          echo '&max_width=200&max_height=120"  align = right/></div>';
        }
        // byline
        $w = get_writer_record($story['writer']);
        echo '<br /><p class="byline">';
        echo $w[full_name].', ';
        echo date('M d, H:i', $story['modified']);
        echo '</p>';
        // main text
        echo $story['story_text'];  
      }
      include_once('footer.php');
    ?>

    Там еще много такого говнеца
    http://www.ibm.com/developerworks/ru/library/l-php_mysql_10/index.html?S_TACT=105AGX99&S_CMP=GR01

    На ЛОРе обсуждают http://www.linux.org.ru/news/doc/6002642

    rO_ot, 12 Марта 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?  
        $result = mysql_query("SELECT date, article, post_text FROM posts");
        while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
            echo "<div class=\"block\">\n\t<span class=\"da_ar\" id=\"left\">\n\t\t".$row[0]."\n\t</span>\n\t<span class=\"da_ar\" id=\"right\">\n\t\t".$row[1]."\n\t</span>\n\t<div class=\"block_text\"><pre>\n".$row[2]."</pre>\n\t</div>\n</div>";
        }
    
        mysql_free_result($result);
    ?>

    Да - да - да, все это в одну строчку...
    Не совсем, конечно, говно, но все же:)

    AlexT, 11 Марта 2011

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

    +169

    1. 1
    global $_GET, $m_db;

    паццтолом

    paranoid, 11 Марта 2011

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

    +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
    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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    $tmp = mysql_query("SELECT DISTINCT (author),(poluchatel) FROM  messages WHERE author='$login' OR poluchatel='$login' ORDER BY  poluchatel,author ",$db); 
                $messages =  mysql_fetch_array($tmp);//извлекаем автора
     if (!empty($messages['author'])) 
    {
    $mass[]='';     // сюда хуячим все имена контактов, всё шо есть в базе
    $security;      // ключ 0,1
    $i=0;          //счетчик
    $white='ffffff';
    $blue='e3ebf8';
    $c=0;
    do //выводим всех авторов
    {
    	$security=1;   //первоначально положительно("1") в каждом цикле на каждый контакт
    if($messages['author']==$login) //если поле автор = тому чья стр
    {
    	$author = $messages['poluchatel'];  //то в пер автор сохраняем имя получателя
    	$mass[$i]=$author;  //кидаем копию имя в массив
    	$i++;	//счетчик ++
    }
    
    else{	//если поле автор не тот  чья стр
    	$author = $messages['author']; //то в пер летит имя отправителя из базы
    	$mass[$i]=$author;	//ебошим всё в массив
    	 $i++;
    		}
    
    for($j=0; $j<=$i; $j++)	//перебераем массив
    {
    
    if($mass[$j]==$messages['poluchatel']) //если в массиве уже есть такой автор
    {$security=0; break;}	//то присваеваем ключ "0"
    }
            if($security==1)	//усли ключ = 1, то выводим контакт
    {
    $result4 = mysql_query("SELECT avatar,id FROM users WHERE login='$author'",$db); //извлекаем аватар автора 
    $myrow4 = mysql_fetch_array($result4);
    if (!empty($myrow4['avatar']))  {//если такового нет, то выводим стандартный (может    этого пользователя уже давно удалили)
    $avatar = $myrow4['avatar'];
    }
    else {$avatar = "avatars/net-avatara.jpg";}
    
    $auth = $messages['author'];  //запоминаем имя этого автора
    $count = mysql_query("SELECT * FROM  messages WHERE author='$auth' AND poluchatel='$login' AND stat='0' " ); //выбираем строки с непрочит соо
    $new_msg=mysql_num_rows($count); //считаем строки
     
    //выставляем цвет фона смс
    //////
    if($c%2==0)
    {
            $color=$blue;
    }
    else
    {
            $color=$white;
    }
    //считаем сообщений от контакта
    $result5=mysql_query("SELECT * FROM messages WHERE  author='$author' AND poluchatel='$login' "); 
    $result6=mysql_query("SELECT * FROM messages WHERE  author='$login' AND poluchatel='$author' ");
    $msg_count1=mysql_num_rows($result5);
    $msg_count2=mysql_num_rows($result6);
    $msg_count=$msg_count1+$msg_count2;
    if($new_msg>0)
    {
             printf("
       <table width='450' bgcolor='f4cf90' >
    <tr>
    <td style='border-bottom:1px solid black'> 
       <a href='page.php?id=%s'><img alt='аватар' width='20px' height='30px' src='%s'></a>
             <a href='my_messages_view.php?author=%s'><font color='0c50a5' style='font-size:17px;font-weight:bold;'>%s</font></a> 
        <font color=red style='font-size:17px;font-weight:bold'>(+%s)</font>
    </td>
     </tr>
    </table>
        ",$myrow4['id'],$avatar,$author,$author,$new_msg);
    }
    else
    {
             printf("
    <table width='450'  bgcolor='".$color."' >
    <tr>
    <td style='border-bottom:1px solid black'> 
      <a href='page.php?id=%s'><img alt='аватар' width='20px' height='30px' src='%s'></a>
      
      <a href='my_messages_view.php?author=%s'><font style='font-size:17px; font-weight:bold;' color='0c50a5'>%s</a></font>
      <font color='6b6b6b' style='font-size:17px; text-align: right; font-weight:bold;'>(%s)</font>
    </td>
     </tr>
    </table>
         ",$myrow4['id'],$avatar,$author,$author,$msg_count);
    	}
      }
      $c++;
      }
         while($messages = mysql_fetch_array($tmp));
            }

    qbasic, 11 Марта 2011

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

    +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
    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
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    <?php
    /*---------------------------------------------------------------------------
    *       @Module Name: Clans
    * @Description: ClanWars for LiveStreet
    * @Version: 1.0
    * @Author: trim06
    * @LiveStreet Version: 0.3.1
    * @File Name: Clans.mapper.class.php
    * @License: GNU GPL v2, http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    *----------------------------------------------------------------------------
    */
     
    class Mapper_Clans extends Mapper {
            public function AddClan($ownerId, $clanName, $nameUrl, $clanPeople, $clanDesc, $urlHomePage, $pathAvatar)
      {
                    $sql = 'INSERT INTO '.DB_TABLE_CLANS.'
                            (owner_id,
                            name,
                            name_url,
          people,
          people_count,
          description,
          reg_date,
          avator,
          url_home_page
                            )
                            VALUES(?d, ?, ?, ?, ?d, ?, NOW(), ?, ?)
                    ';
        $clanPeopleCount = count(explode(',', $clanPeople));
                    if($this->oDb->query($sql, $ownerId, $clanName, $nameUrl, $clanPeople, $clanPeopleCount, $clanDesc, $pathAvatar, $urlHomePage))
        {
                        $this->DropInviteClanCreate($ownerId);
                            return true;
                    }               
                    return false;
            }
      
            public function UpdateClan($clanId, $ownerId, $clanPeople, $clanName, $nameUrl, $clanDesc, $urlHomePage, $pathAvatar)
      {
                    $sql = 'UPDATE '.DB_TABLE_CLANS.' 
                            SET 
            name = ?,
            name_url = ?,
            people = ?,
            description = ?,'.
            (($pathAvatar) ? "avator = '".$pathAvatar."'," : '').
            'url_home_page = ?,
            people_count = ?d
                            WHERE
                                    owner_id = ?d AND id = ?d
                    ';
        $clanPeopleCount = count(explode(',', $clanPeople));
                    if ($this->oDb->query($sql, $clanName, $nameUrl, $clanPeople, $clanDesc, $urlHomePage, $clanPeopleCount, $ownerId, $clanId))
        {
                            return true;
                    }               
                    return false;
            }
      public function GetClans($status,&$iCount,$iCurrPage,$iPerPage)
      {
        $sql = 'SELECT * FROM '.DB_TABLE_CLANS.' WHERE status=?d 
    AND id NOT IN (SELECT clan_id
                    FROM '.DB_TABLE_CLANS_BANS.'
                    WHERE ban_active=1
                    GROUP BY clan_id)
    ORDER BY rating DESC LIMIT ?d, ?d';
        $status = ($status=='good') ? 0 : 1;
        if($aRows=$this->oDb->selectPage($iCount, $sql, $status, ($iCurrPage-1)*$iPerPage, $iPerPage))
        {
          return $aRows;
        }
        return null;
      }
    public function GetBannedClans(&$iCount,$iCurrPage,$iPerPage)
      {
        $sql = 'SELECT c.* 
            FROM  
            (SELECT clan_id
                    FROM '.DB_TABLE_CLANS_BANS.'
                    WHERE ban_active=1
                    GROUP BY clan_id) as cb
            JOIN '.DB_TABLE_CLANS.' as c ON c.id=cb.clan_id
            ORDER BY rating 
            DESC LIMIT ?d, ?d';
        if($aRows=$this->oDb->selectPage($iCount, $sql, ($iCurrPage-1)*$iPerPage, $iPerPage))
        {
          return $aRows;
        }
        return null;
      }

    qbasic, 11 Марта 2011

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

    +161

    1. 1
    2. 2
    $iMin = $page - (($page<=$limiter)?$page-1:$limiter) + ((($pagesCount-$page)<$limiter)?($pagesCount-$page-$limiter):0);
    $iMax = $page + ((($pagesCount-$page)<$limiter)?$pagesCount-$page:$limiter) + (($page<=$limiter)?$limiter-$page:0);

    -ggorky, 10 Марта 2011

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

    +172

    1. 1
    2. 2
    3. 3
    foreach($shop_search_arr as $k=>$v){
    	$shop_search_arr[$k] = $v;
    }

    Чтоб наверняка)

    jfhs, 10 Марта 2011

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