I have a PHP Session that I am using to manage my administration panel of my website. This uses two variables to monitor the session, lastAction and user. Recently, on one particular page of my website, the session variable user will randomly unset entirely and send the user back to the login page, but I cannot seem to figure out why.
session_start();
$fn = "timeout.txt";
$fh = fopen($fn,'r');
$to = fread($fh,filesize($fn));
if(abs(time()-$_SESSION["lastAction"]) > $to)
{
session_unset();
die("Timeout");
}
var_dump($_SESSION);
//Set timeout back to 0
$_SESSION["lastAction"] = time();
if($_SESSION["user"] != "...")
{
die("Invalid User");
header("Location:/login");
}
I never get the Timeout error, only the Invalid User error.
Sometimes when I dump the session variable, I get the array of two values, lastAction and user, but then, simply by reloading the page only a few seconds later, user gets unset, but lastAction does not.
Also, in this instance, I am reloading the page through javascript: parent.location='';
Any ideas on what might be causing this?