一次只允许一个会话 [英] Allow one session only at a time

查看:43
本文介绍了一次只允许一个会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的网站一次只允许一个会话.例如,假设用户在firefox上登录了我的网站,如果用户在同一台​​计算机或不同计算机上再次登录到另一个浏览器,如opera,firefox上的会话将被破坏.但是,firefox 上的会话仍然保留为一个会话.我可以知道我该怎么做吗?我正在使用 php 和 apache.谢谢.

I would like to make my website to allow only one session at a time. For example, let say user has login to my website on firefox, if the user login again to another browser like opera on the same computer or different computer, the session on firefox will be destroyed. However, the session on firefox remained if it remains as one session. May I know how can I do that? I am using php and apache. Thank you.

问候.本杰明

推荐答案

我建议你这样做:

假设用户A"第一次登录Com_1".在数据库中针对该会话保存一个唯一代码,与用户会话相同.

Suppose when user "A" loges in to the "Com_1", for the first time. Save a unique code in the database against that session, and same with the user session.

与此同时,如果他(用户A")再次登录com_2",则检查他在数据库中的状态并更新数据库中的唯一代码.

At the mean time if he (user "A") loges in again on "com_2", then check his status in the database and update the unique code in the database.

如果同一用户(用户A")刷新com_1"上的页面,我们只需检查会话中的唯一代码并将其与数据库匹配,肯定不会匹配,然后注销并销毁会话.

again back if same user (user "A") refreshes the page on "com_1", we all you need to do is check the unique code from the session and match it to the database, It is for sure it will not match, then log it out and destroy the session.

为了保持用户登录,即使浏览器关闭,您可以将cookie存储在浏览器上,并相应地重新生成会话.

For keeping the user loggedin, even if browser is closed, you can store the cookie on the browser, and re-generate the session accoordingly.

希望这会有所帮助.谢谢.

Hope this helps. Thank you.

这篇关于一次只允许一个会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆