PHP/会话:每个用户登录一个? [英] PHP /SESSION: Login one per user?
问题描述
我该怎么做,当时1个用户只能在线1个?想法?
How can i do so only 1 can be online for the 1 user at the time? Idea ?
因此您无法在一个PC/浏览器上登录到User1,然后在另一PC/浏览器上登录到User1?
So you e.g can not login to User1 on one pc/browser and then on the other pc/browser login to User1?
我的社区系统使用PHP,并且存储在会话中..
I have my communitysystem in PHP, and it stores in sessions..
推荐答案
您可以将会话ID(和上次访问时间)存储在数据库中,如果上次访问时间为,则拒绝具有不同会话ID的用户的登录尝试.太新了(例如,过去20分钟内).当然,注销时清除ID.
You could store the session ID (and last access time) in a database, and reject login attempts for users with different session IDs if the last-access time is too recent(say, within the past 20 minutes). Clear the ID on logout, of course.
但是请注意,如果用户没有注销就关闭浏览器然后重新打开,则很可能会被锁定一段时间(以上20分钟或您确定的间隔),因为他们没有匹配的会话Cookie了.
Note, though, if a user closes their browser without logging out and then reopens it, they may well be locked out for a while (the 20 minutes above, or whatever interval you decide on), since they won't have the matching session cookie anymore.
这篇关于PHP/会话:每个用户登录一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!