试图登录过去10天

时间:2010-07-22 20:46:02

标签: php

我正在使用登录系统,我试图让用户登录10天,除非他们专门注销。我想通过使用session_set_cookie_params('864000');它会让用户保持登录状态10天。但它并没有这样做,至少在Chrome中是这样。在自动注销之前,用户似乎仅在标准的20-30分钟内登录。当我在Chrome中检查Cookie时,我的网址列出了两个PHP会话Cookie,其中有效日期为未来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;
}

1 个答案:

答案 0 :(得分:0)

您的服务器更有可能丢弃会话 - 您需要将相关信息存储在本地友好数据库中,并根据相应的Cookie从那里加载

相关问题