I am trying to code an automatic session timeout function in php, currently, this is what i have
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1200)) {
// last request was more than 20 minutes ago
// destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
This technique depends on the user loading a page before he is notified of his expiration and i need to check on pageload.
I need one that expires weather the user loads a page or not. This is because other users loggedin to the site are notified when a session expires, and data is recorded in the database for further use.