基于SSL的用户登录系统cookie


user login system cookie based over ssl

>我创建了用户登录系统,并使用此功能启动会话

function sessionStart() {
    $session_name = 'sec_session_id'; // Set a custom session name
    $secure = false; // Set to true if using https.
    $httponly = true; // This stops javascript being able to access the session id. 
    ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies. 
    $cookieParams = session_get_cookie_params(); // Gets current cookies params.
    session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly); 
    session_name($session_name); // Sets the session name to the one set above.
    session_start(); // Start the php session
    session_regenerate_id(true); // regenerated the session, delete the old one. 
}

使用会话 cookie,就像您在上面提到的功能中看到的那样,我将此会话存储在 memcached 中以提高我的操作。现在我需要创建一个在其中存储用户数据的 cookie。例如,我需要用户 ID,然后我将用户 ID 存储在这样的 cookie 中

setcookie('userid','1234',time()+240000)
之后,我需要用户密码

和用户名,以防用户保持登录状态。但我知道我不应该将密码保留在cookie中。如果我们的服务器因使用memcache而崩溃时没有在cookie中保留密码,我们将失去所有用户 session.am 对吗?那么我应该如何保持用户登录。.请只是 explain.no 需要费心编写代码。

提前致谢

我建议您将客户端登录的数据保存在 SQL 数据库中,并为 SQL 行提供一个随机的盐 + 哈希,然后将该哈希分配给 cookie。然后,您只需每次从数据库中获取信息即可。