I am trying to write an automatic logout script that seems to work, but does not meet my expectations, I donβt know what I am doing wrong, I want to put timeout.php on each page so that when the user does not work, he automatically logs out and forwards it to the page login , but when I put timeout.php to my page add users, where an administrator adds a user, overriding the link to add to your user page and putting login page which also goes nicely (ie in the form of goes from its position) 
this is timeout.php code
<?php $_SESSION = 0; if($_SESSION['session_count'] == 0) { $_SESSION['session_count'] = 1; $_SESSION['session_start_time']=time(); } else { $_SESSION['session_count'] = $_SESSION['session_count'] + 1; } $session_timeout = 10; // (in sec) $session_duration = time() - $_SESSION['session_start_time']; if ($session_duration > $session_timeout) { session_unset(); session_destroy(); session_start(); session_regenerate_id(true); $_SESSION["expired"] = "yes"; header("Location: login.php"); // Redirect to Login Page } else { $_SESSION['session_start_time']=time(); } ?>
I want him to automatically log out and redirect himself to the expired login page, and I want him to put it on every page without breaking the form or blocking the page.
source share