[英]automatic log out user when someone login another user from one account
can someone help me?有人能帮我吗? I want to automatically log out the user when someone login another user to their account and the page will automatically reload and the user will be logged out and go to the login form.当有人将另一个用户登录到他们的帐户时,我想自动注销用户,页面将自动重新加载,用户将被注销并转到登录表单。 My code below is needed to refresh the page to validate the user session token is equal to the token in the database.我需要下面的代码来刷新页面以验证用户会话令牌是否等于数据库中的令牌。
if($_SESSION['token'] != $usertoken){
session_destroy();
unset($_SESSION['user']);
header("location: /login");
exit();
}
You can either try WebSockets or Server-Side-Events with PHP.您可以使用 PHP 尝试 WebSockets 或服务器端事件。
Here are good examples to set up server side events with JS/PHP:以下是使用 JS/PHP 设置服务器端事件的好示例:
https://www.w3schools.com/html/html5_serversentevents.asp https://www.w3schools.com/html/html5_serversentevents.asp
So you could check every 5 seconds if a new user has been logged in and log the other user out.因此,您可以每 5 秒检查一次新用户是否已登录并注销其他用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.