2010-07-22 57 views
0

我正在使用登錄系統,並且我試圖讓用戶登錄10天,除非他們明確註銷。我想通過使用session_set_cookie_params('864000');它會讓用戶保持登錄狀態10天。但至少在Chrome中這並不是這樣做的。用戶似乎只能在自動註銷之前以20-30分鐘的標準登錄。當我在Chrome瀏覽器中查看cookies時,我的URL中會列出兩個PHP會話Cookie,並在將來10天內有效日期。但是這似乎與登錄變量無關。大部分相關的代碼應該在下面。試圖獲得最近10天的登錄

任何想法爲什麼用戶未登錄10天?

由於提前,

約翰

在索引文件中,我有以下幾點:

require_once "header.php"; 
//content 
include "login.php"; 

在header.php文件,下面是包括:

session_set_cookie_params('864000'); 
session_start(); 

在login.php文件中包含以下內容:

if (checkLogin($_POST['username'], $_POST['password'])) 
     { 
      show_userbox(); 


     } 

下面是函數「checkLogin」:

function checkLogin($u, $p) 
{ 
global $seed; // global because $seed is declared in the header.php file 

    if (!valid_username($u) || !valid_password($p) || !user_exists($u)) 
    { 
     return false; // the name was not valid, or the password, or the username did not exist 
    } 

    //Now let us look for the user in the database. 
    $query = sprintf(" 
     SELECT loginid 
     FROM login 
     WHERE 
     username = '%s' AND password = '%s' 
     AND disabled = 0 AND activated = 1 
     LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed))); 
    $result = mysql_query($query); 
    // If the database returns a 0 as result we know the login information is incorrect. 
    // If the database returns a 1 as result we know the login was correct and we proceed. 
    // If the database returns a result > 1 there are multple users 
    // with the same username and password, so the login will fail. 
    if (mysql_num_rows($result) != 1) 
    { 
     return false; 
    } else 
    { 
     // Login was successfull 
     $row = mysql_fetch_array($result); 
     // Save the user ID for use later 
     $_SESSION['loginid'] = $row['loginid']; 
     // Save the username for use later 
     $_SESSION['username'] = $u; 
     // Now we show the userbox 
     return true; 
    } 
    return false; 
} 

回答

0

看起來更可能是您的服務器丟棄會話 - 你需要的相關信息在當地友好的數據庫和存儲負載從那裏,酌情根據餅乾