I am aware that similar questions have been asked, but none seem to have a good solution. I have a auto logout function ( see below).
However if the tab/browser is closed, the session is never destroyed, and more importantly the DB table tblTimeLog
is not updated.
What I want to do is for the "timer to keep running" even tho the browser or tab is closed. Any suggestions on how to achieve this?
Auto logout function:
<?
session_start();
// set timeout period in seconds
$idleTime = 2400;
header("refresh: 2400");
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $idleTime) {
$db->Execute("UPDATE tblTimeLog SET LogoutTime = NOW() WHERE sid ='".session_id()."'".$row['konsulentid'].'');
session_destroy();
header("Location: login.php?loggut");
exit();
}
}
$_SESSION['timeout'] = time();
?>