I have created a simple login page which is based on the sessions.
session_start();
and added a logout page that contains this
Server can't detect browser or tab closed, you could use Javascript or Ajax but sorry I don't have knowledge about that.
My suggestion is use Session Timeout, so session will be destroyed if there's no action from user. This is an example :
// destroy every 2 minutes
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 120)) {
// last request was more than 2 minutes ago
session_destroy(); // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
// end of code
Hope this help you