За последние 24 часа нас посетили 20206 программистов и 1708 роботов. Сейчас ищут 1707 программистов ...

Немогу разобраться с кукисами

Тема в разделе "PHP и базы данных", создана пользователем _virus_, 9 июн 2010.

  1. _virus_

    _virus_ Активный пользователь

    С нами с:
    23 июн 2009
    Сообщения:
    30
    Симпатии:
    0
    Адрес:
    с.Александровское Томской обл.
    Хочу сделать, чтобы пароль и логин записывался в кукисы, вписал туда

    setCookie("c_user_name", $user_name, time() + 2678400);
    setCookie("c_password", $user_pass, time() + 2678400);

    В переменную c_user_name всё норм записывает, а вот в c_password не хочет, в чём ошибка?

    Вот функция set_variable();

    PHP:
    1.  
    2. function set_variable($variable_name) {
    3.         global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $$variable_name;
    4.         $$variable_name = "";
    5.         //GPC order :)
    6.         if (isset($HTTP_GET_VARS[$variable_name])) $$variable_name = $HTTP_GET_VARS[$variable_name];
    7.         if (isset($HTTP_POST_VARS[$variable_name])) $$variable_name = $HTTP_POST_VARS[$variable_name];
    8.         if (substr($variable_name,0,2)=="c_" && isset($HTTP_COOKIE_VARS[$variable_name])) $$variable_name = $HTTP_COOKIE_VARS[$variable_name];
    9.         //i don't use string-arrays in forms, only in the admin-zone, but there it's just design &lang names
    10.         //which is normally doesn't have ' or " etc
    11.         if (is_string($$variable_name)) {
    12.                 $$variable_name = str_replace("\0","", $$variable_name);
    13.                 $$variable_name = str_replace("\t"," ", $$variable_name);
    14.                 if (get_magic_quotes_gpc()) $$variable_name = stripslashes($$variable_name);
    15.         }
    16. }
    17.  
    А вот код страницы
    PHP:
    1.  
    2. <?php
    3. require_once("inc_common.php");
    4. set_variable("session");
    5. set_variable("c_user_name");
    6. set_variable("user_name");
    7. set_variable("c_password");
    8. set_variable("password");
    9. if(!$user_name) $user_name = $c_user_name;
    10. if(!$password) $password = $c_password;
    11. $design = $default_design;
    12. if ($session != "") {
    13.     include($engine_path."users_get_list_love.php");
    14.  
    15.     if (!$exists) {
    16.                 $error_text = "$w_no_user";
    17.                 include($file_path."designes/".$design."/error_page.php");
    18.                 exit;
    19.     }
    20.  
    21.     include_once("inc_user_class.php");
    22.     include($engine_path."users_get_object.php");
    23.  
    24.         $registered_user = $is_regist;
    25.  
    26.         include($engine_path."user_din_data_update_love.php");
    27. if($user_name) setCookie("c_user_name", $user_name, time() + 2678400);
    28. if($password) setCookie("c_password", $password, time() + 2678400);
    29. include("design_love.php");
    30.         exit;
    31.  }
    32.  
    33. $TryToBeInvisible = false;
    34. if(strlen($user_name) > 0) {
    35.         if(substr($user_name, 0, 1) == "*") {
    36.        $user_name = substr($user_name, 1);
    37.        $TryToBeInvisible = true;
    38.     }
    39. }
    40.  
    41. include("inc_user_class.php");
    42. //end DD
    43.  
    44. setCookie("c_ulang", $user_lang, time() + 2678400);
    45.  
    46.  
    47. include("inc_to_canon_nick.php");
    48. #check for nickname;
    49.  
    50. if ((strlen($user_name)<$nick_min_length) or (strlen($user_name)>$nick_max_length)) {
    51.         $error_text ="$w_incorrect_nick<br><a href=\"index.php\">$w_try_again</a>";
    52.         include($file_path."designes/".$design."/error_page.php");
    53.         exit;
    54. }
    55. if (ereg("[^".$nick_available_chars."]", $user_name)) {
    56.         $error_text ="$w_incorrect_nick<br><a href=\"index.php\">$w_try_again</a>";
    57.         include($file_path."designes/".$design."/error_page.php");
    58.         exit;
    59. }
    60. if (strtolower($user_name) == strtolower(strip_tags($w_rob_name))) {
    61.         $error_text ="$w_incorrect_nick<br><a href=\"index.php\">$w_try_again</a>";
    62.         include($file_path."designes/".$design."/error_page.php");
    63.         exit;
    64. }
    65.  
    66.  
    67.          $canon_view    = to_canon_nick($user_name);
    68.          $old_user_name = $user_name;
    69.          include($engine_path.'users_get_list_love.php');
    70.          $user_name = $old_user_name;
    71.  
    72.          $session = '';
    73.          for($i = 0; $i < count($users); $i++) {
    74.             $user_array  = explode("\t", trim($users[$i]), USER_TOTALFIELDS);
    75.             if (strcmp($user_array[USER_CANONNICK],$canon_view) == 0) {
    76.                 $session = $user_array[USER_SESSION];
    77.                 break;
    78.             }
    79.          }
    80.  
    81.          if($session == '') $session = md5(uniqid(rand()));
    82.          
    83. $registered_user = 0;
    84. $users = array();
    85. $htmlnick = "";
    86. include($ld_engine_path."voc_user_data.php");
    87.  
    88. if (!$registered_user) {
    89.               echo "Такой пользователь не зарегистрирован";
    90.               exit;
    91. }
    92.  
    93.  
    94. //DD Levandovka fix :-)
    95. if($current_user->user_class == 0 and $TryToBeInvisible) $TryToBeInvisible = false;
    96.  
    97. if($current_user->custom_class != 0) $user_custom_class = $current_user->custom_class;
    98.  
    99. //DD updating userinfo
    100. $is_regist                                = $registered_user;
    101. $current_user->IP                         = $IP;
    102.  
    103. $current_user->browser_hash = $browser_hash;
    104. $current_user->cookie_hash  = $c_hash;
    105. $current_user->session      = $session;
    106. if(isset($_SERVER["HTTP_USER_AGENT"])) $current_user->user_agent   = htmlspecialchars($_SERVER["HTTP_USER_AGENT"]);
    107. else $current_user->user_agent   = htmlspecialchars($HTTP_SERVER_VARS['HTTP_USER_AGENT']);
    108.  
    109.  
    110. include($ld_engine_path."user_info_update.php");
    111.  
    112.  
    113. //updating the similar nicks table
    114. $similars = array();
    115. $fp1 = fopen($data_path."similar_nicks.tmp", "ab+");
    116. if (!$fp1) trigger_error("Could not open ".$data_path."similar_nicks.tmp"." for writing. Please, check permissions", E_USER_ERROR);
    117. if (!flock($fp1, LOCK_EX))
    118.         trigger_error("Could not LOCK ".$data_path."similar_nicks.tmp"." file. Do you use Win 95/98/Me?", E_USER_WARNING);
    119. fseek($fp1,0);
    120. $isNickFoundInSimilars = false;
    121. while ($data = fgets($fp1, 4096)) {
    122.         $u_data  = explode("\t",str_replace("\r","",str_replace("\n","",$data)));
    123.  
    124.         $tov = 0;
    125.         for($i = 0; $i < count($current_user->photo_voted); $i++) {
    126.                $tov += $current_user->photo_voted_mark[$i];
    127.         }
    128.  
    129.         if ($u_data[0] == $is_regist) {
    130.                 $u_data[2] = $current_user->password;
    131.                 $u_data[3] = $current_user->email;
    132.                 $u_data[4] = $current_user->IP;
    133.                 $u_data[5] = $current_user->browser_hash;
    134.                 $u_data[6] = $current_user->cookie_hash;
    135.                 $u_data[7] = $current_user->points;
    136.                 $u_data[8] = $current_user->online_time;
    137.                 $u_data[9] = $current_user->credits;
    138.                 $u_data[10] = $tov;
    139.                 $isNickFoundInSimilars = true;
    140.         }
    141.         $similars[] .= implode("\t",$u_data) . "\n";
    142. }
    143.  
    144. if($user_name) setCookie("c_user_name", $user_name, time() + 2678400);
    145. if($password) setCookie("c_password", $password, time() + 2678400);
    146. include($engine_path."voc_love.php");
    147.  
    148. include("design_love.php");
    149. ?>
    150.  
     
  2. Scorpius

    Scorpius Активный пользователь

    С нами с:
    6 май 2010
    Сообщения:
    59
    Симпатии:
    0
    Адрес:
    там уже нет
    Это для совместимости с третим PHP?)
     
  3. _virus_

    _virus_ Активный пользователь

    С нами с:
    23 июн 2009
    Сообщения:
    30
    Симпатии:
    0
    Адрес:
    с.Александровское Томской обл.
    Блин я незнаю, но с c_user_name же работает!