How can i do so only 1 can be online for the 1 user at the time? Idea ?
So you e.g can not login to User1 on one pc/browser and then on the other pc/browser login to
This solution doesn't require you to access the database on every page and doesn't lock out the user after they failed to log out.
Add a field for sessionID to your user table in the database.
Set the default session handler before calling session_start():
session_set_save_handler(new \SessionHandler());
On every successful login, retrieve the stored $sessionID from the database. Destroy the old session with:
(new \SessionHandler())->destroy($sessionID);
Get the new session ID with:
$sessionID = session_id();
Store the new session ID to the database.