且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在php中循环遍历会话数组

更新时间:2023-01-16 20:47:01

$ _ SESSION仅适用于实际打开页面的访问者. (很高兴看到每个人的$ _SESSION变量,对吗?)

$_SESSION is available only for the visitor who opens the page actually. (It would be nice to see everyone's $_SESSION variables, isn't it?)

您可能希望将这些$ _SESSION变量存储在数据库中,然后遍历它们.

You may want to store these $_SESSION vars in your db then loop through them.

更新:

  • 创建一个会话表,您可以在其中存储当前登录的用户
  • 每次登录的用户打开页面时,都增加一个值(时间戳),如last_seen
  • 同时检查无效会话(例如,删除last_seen值小于now的所有行-服务器的会话寿命
  • create a sessions table where you can store your currently logged in users
  • every time when a logged in user opens a page, increment a value (timestamp) like last_seen
  • at the same time check dead sessions (e.g. delete all rows where last_seen value is smaller than now - server's session lifetime