if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > SESSION_TIMEOUT)) { // SESSION_TIMEOUT is the amount of time you want the session to be. session_unset(); session_destroy(); header('Location: login.php'); } $_SESSION['LAST_ACTIVITY'] = time();
Add this to your page. The if statement checks if the session has expired and redirects the user to loginpage.php. Otherwise, it just updates the session time
Of course you change things to cookie syntax. Missed that I use sessions and you need a cookie.
source share