简体   繁体   English

php session_destroy全部清除所有会话,除了运行代码的会话

[英]php session_destroy all clear all sessions except the one running the code

I have been looking for a way to log all my users out except the one activating this command? 我一直在寻找一种方法来注销所有用户,除了激活该命令的用户? if there a way to do this... I have the following code below but I am not even sure if it 100% works as it said "try" 如果有办法做到这一点...我在下面有以下代码,但我什至不确定它是否100%有效,因为它说“ try”

ini_set('session.gc_max_lifetime', 0);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1);

So I want to clear all the sessions (session_destroy) on each session except for the session viewing the page?? 所以我想清除每个会话上的所有会话(session_destroy),但查看页面的会话除外? is this possible.. 这可能吗..

I think in this case more right way - create custom code to logout all users. 我认为在这种情况下,更正确的方法-创建自定义代码以注销所有用户。 For example I can suggest this solutions: 例如,我可以建议以下解决方案:

  1. You can store in database special parameter last_users_logout_time and when user login then store in $_SESSION array variable user_login_time . 您可以将特殊参数last_users_logout_time存储在数据库中,并在用户登录时将其存储在$ _SESSION数组变量user_login_time And in every page you can check if user_login_time < last_users_logout_time or user_login_time is null then logout user. 并且在每个页面中,您可以检查user_login_time < last_users_logout_timeuser_login_time是否为null,然后注销用户。 Very simple. 很简单。 For ignore specified user you can add parameter except_logout_user_id into database 对于忽略指定的用户,您可以将参数except_logout_user_id添加到数据库中

  2. More "right way" - store $_SESSION data in database and just run DELETE query for all session table except specified user 更“正确的方法”-将$ _SESSION数据存储在数据库中,并且只对所有session表(指定用户除外)运行DELETE查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM