I have this php code to log out after 30 Minutes of inactivity in my index.php:
<?php
session_start(); /* Starts the session */
if(!isset($_SESSION['UserData']['Username'])){
header("location:login.php");
exit;
}
else
{
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
header("location:login.php?session_timeout");
exit;
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
}
?>
This code is on top of every protected page. As long as I reload this page the inactivity counter is updated, and also the logout does happen.
The problem is, all the other code in my webpage is written in js and jQuery, so the page never really get's refreshed, and so does the php code never executes. That leads to an not updated inactivity tiemer and I also don't get logged out.
Is there a possibility to change this behaviour?
Thanks!