登出各地,我还登其他地方 [英] Log out everywhere, where else I am logged in

查看:86
本文介绍了登出各地,我还登其他地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用PHP会话作为我的用户登录系统的基础,成功的登录设置为$ _SESSION ['userid'].这样一来,用户就可以从多台计算机登录到同一帐户.

I currently use PHP sessions as the basis of my user login system, with a successful login setting $_SESSION['userid']. This allows a user to log in to the same account from multiple machines.

但是,我想实现以下功能:

However, I'd like to implement the following features:

  1. 注销到任何地方,类似于Stack Overflow的内容.
  2. 查看其他人登录的地方.

这两者都可能需要的不仅仅是会话变量,而且我愿意将更多信息放入数据库中以实现这些目的.进行上述操作的标准方法是什么?

Both will likely require more than just a session variable, and I'm willing to put more information into the database to accomplish these. What is a standard way to do the above?

推荐答案

创建一个新的数据库表来存储会话,然后直接在新会话中存储指向行的ID,而不是直接在$_SESSION中存储信息.桌子.该表可以包含IP地址,用户名和上次活动时间等信息.

Create a new database table to store sessions, and then instead of storing information directly in $_SESSION, just store an ID referring to a row in your new session table. This table can contain information like IP address, username, and the time of last activity.

您的应用程序应对照$_SESSION中的会话表检查会话表,因此,当删除特定用户的表中的所有行时,无论会话在哪里,每个会话都会失效.您还可以查询属于特定用户的所有行,因此可以显示他们具有活动会话的位置.

Your application should check the sessions table against what it has in $_SESSION, so when you remove all rows in the table for a particular user, every session will be invalidated, wherever it is. You can also query for all rows belonging to a particular user, so you can show where they have active sessions.

您必须开始考虑如何处理用户离开会话的位置而无需显式注销-可能是每小时或每天运行的计划作业,清除在一段时间内没有任何活动的会话行.时间.

You'll have to start thinking about handling where a user leaves their session without explicitly logging out - possibly a scheduled job that runs every hour or day, clearing out session rows that haven't had any activity in a certain period of time.

这篇关于登出各地,我还登其他地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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