I have a user login which is only valid for 1 hour. I mean the user can login to the system and he can keep doing his works. I am not gonna check the inactive time. I start the calculation from the very beginning of the process where user successfully logged in.Whatever the user doing, I will cache the actions and destroy the session and direct to the log in section for each and every 1 hour after the log in.
When user successfully logged in, i set the timestamp to a $_SESSION
variable in following manner.
$_SESSION['key_set_time'] = time();
.
The following is the SESSION DESTROY code.
$_SESSION['key_set_time'] = time();
$session_duration = 3600;
$current_time = time();
if(((time() - $_SESSION['key_set_time']) > $session_duration)){
session_destroy();
}else{
header('LOCATION:/login.php');
}
While debugging I found out that $_SESSION['key_set_time'] = time();
sets the current time in each every page reload.It replaces the time when the user logged in.So I am unable to DESTROY the session. How can I prevent the replacing the time in every page reload?
( This process has to be done in the BACKEND ITSELF. This noob note is because of a stackoverflow answer which is to destroy the SESSION MANUALLY.)