[英]PHP: Delete another session given the id
I have the following problem: 我有以下问题:
In this way, two users get access as the same user, in different PCs, and different session ids. 通过这种方式,两个用户可以作为同一个用户,不同的PC和不同的会话ID进行访问。 What I wanna do is store the new session_id each time a user login (done), and delete the previously stored session_id.
我想做的是每次用户登录(完成)时存储新的session_id,并删除先前存储的session_id。 But I don't know how to delete or modify a session file given the id, without changing the current session.
但我不知道如何删除或修改给定id的会话文件,而不更改当前会话。
I mean, I wanna do the following: 我的意思是,我想做以下事情:
Can *session_id(old_session)* work properly? 可以* session_id(old_session)*正常工作吗? Or that function just rename the current session id, but mantain the values?
或者该函数只是重命名当前的会话ID,但保留值?
Thanks in advance. 提前致谢。
I found this 我找到了这个
$session_id_to_destroy = $sessionid;
// 1. commit session if it's started.
if (session_id()) {
session_commit();
}
// 2. store current session id
session_start();
$current_session_id = session_id();
session_commit();
// 3. hijack then destroy session specified.
session_id($session_id_to_destroy);
session_start();
session_destroy();
session_commit();
// 4. restore current session id. If don't restore it, your current session will refer to the session you just destroyed!
session_id($current_session_id);
session_start();
session_commit();
It worked perfectly for me. 它对我来说很完美。
From my experience, I use one table to store data related to the session. 根据我的经验,我使用一个表来存储与会话相关的数据。 The table contains two or more fields of userID, lastSessionID.
该表包含两个或多个userID,lastSessionID字段。 On your system just need to get the sessionId and userID then compare it to the last sessionID stored in the db refers to the same userID.
在您的系统上只需要获取sessionId和userID然后将其与存储在db中的最后一个sessionID进行比较,即指向相同的userID。 If U get the same sessionID than continue but if different redirect page to logout.
如果U获得的会话ID与继续相同,但是如果不同的重定向页面要注销。 But, to use this method, you should keep a userID and sessionId into the db every time user login.
但是,要使用此方法,每次用户登录时都应将userID和sessionId保留在db中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.