I have created a script login.php
and there I have created a session variable named logged_in
$_SESSION['logged_in'] = true;
I am unable to figure out a way to redirect to redirect to my logout.php after session expires due to inactivity. Also should I put the code that expire this session variable. I have Googled the bug and what it suggest is to tweak php.ini
file in most of the articles. However I came across an article saying that it is not the best practice.
I found the following code on StackOverflow, yet I have no idea where to put it:-
<?php
if ($_SESSION['timeout'] + 10 * 60 < time()) {
// session timed out
} else {
// session ok
}
?>
I would like to know the best way to redirect after session expire and suggestions for where to put the code.
Edit: I forgot to mention that I want to know how to manually set a time for the session to expire.
Thank you in advance