I am creating the login for my application. It's working, but there's a problem. I log in, and then stay idle for some time automatically logs out the user session, but does not redirect to the login page. Besides not redirecting it still allows to make records in the database without the user being logged in.
I'm trying to resolve it this way, but it will not let me sign in:
session_start();
session_cache_limiter(1);
$limite=60;
session_start();
if(isset($_SESSION['tempolimite']) ){
if ( time() > $_SESSION['tempolimite']){
header("Location: sair.php");
}
}else{ // Primeira visita
$_SESSION['tempolimite']=time()+$limite;
}
echo "<h4 style='float: right; margin-right: 3%;'>Seja bem-vindo, ". $_SESSION['usuarioNome']."</h4>";
I'm trying another way:
First I put this line in the page where I start the session:
$_SESSION['login_time'] = time();
Then on the page where I make the registration I put this code:
session_start();
if(time() - $_SESSION['login_time'] >= 25){
session_destroy(); // destroy session.
header("Location: sair.php");
die(); // See https://thedailywtf.com/articles/WellIntentioned-Destruction
//redirect if the page is inactive for 30 minutes
}
else {
$_SESSION['login_time'] = time();
// update 'login_time' to the last time a page containing this code was accessed.
}
echo "<h4 style='float: right; margin-right: 3%;'>Seja bem-vindo, ". $_SESSION['usuarioNome']."</h4>";
It works, but I have to refresh the page manually, otherwise refresh keeps the page available and able to register. How can I do when to pass the time limit redirect automatically without having to refresh the page?