I am writing a project in PHP, JavaScript and HTML. I have successfully done the automatic logout when the user is idle for 1 minute. But the problem comes in that I have to refresh the page for it to be executed and log me out.
Can somebody help me so that immediately 1 minute is over and the user is idle, the code will be executed and it will take me to the login page without me refreshing it?
Here is my code:
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{
echo"<script type='text/javascript'>
window.alert('Your Session got Expired');
</script>";
header("Location: logout.php");
}
}
$_SESSION['timeout'] = time();
//Continuation of other codes