简体   繁体   English

当有人从一个帐户登录另一个用户时自动注销用户

[英]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.

相关问题 来自用户帐户数据库的自动电子邮件 - automatic emails from user account database 用户登录网站时从Android应用注销用户 - Log out user from Android app when user signs in on website 未登录用户的“登录”值和已登录用户的“注销”值 - 'Login' value for non logged user and 'Log Out' value for logged in user 从一个用户账户转账到另一个用户账户 - Transfer amount from a user account to another user account MS Exchange-以一个用户身份登录并使用TLS从另一个用户发送 - MS Exchange - login as one user and send from another with TLS PHP Logout不会在用户注销时从用户所在的页面中注销用户 - PHP Logout won't log user out from the page the user was on, when they logged out 我需要从我的管理员帐户登录到另一个用户而没有密码 - I need to log in to another user from my Admin account without a password 当用户点击链接时,如何传输登录信息并自动登录到其他网站? - How to transfer login information and automatically log to another website, when user click on link? 如何更改登录名 <li> 用户登录同一页面时使用另一种CSS设计 - How can I change the login <li> with another css design, when the user log in in the same page 从php会话注销用户 - Log out user from php session
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM