简体   繁体   中英

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.

Here are good examples to set up server side events with JS/PHP:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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