I'm trying to determine when a session has expired, and if so, delete it and start a new one. Here is the relevant code:
/********************************/
if (isset($_COOKIE['MYSESSID']))
{
$result = mysql_query("SELECT expiration FROM ".$session." WHERE SID='".session_id()."'");
$row = mysql_fetch_object($result);
if ((time() - $row->expiration) > 0) //current time is past the expiration
{
session_name('MYSESSID');
session_start(); //because this must be present before destroying the session
$_SESSION = array();
session_destroy();
}
}
//now start a new session
session_name('MYSESSID');
session_start();
/*************************************/
So, as you can see, I'm using mysql session handlers. What I'm doing is taking the operation time()-expiration. If this is negative, the current time has not reached the expiration time of the session and everything is ok. If this is > 0, the current time is past the expiration and the session is no longer valid. So I try to delete the session and start a new one. However, when I start a session, let it sit until it expires, and then try to resume surfing, I get this error:
Fatal error: Failed to initialize session module in header.php on line 55
header.php is the line that launches the session. Part of the code is what is given above. Line 55 is the last line in the above code block.
Does anyone know why this is happening. I have tried many other things but all give the same result. Is there anyway to seamlessly start a new session once an old one expires? Kinda like a website that requires you to login, then tells you to relogin once it detects the session has expired. How do they do this (I don't need the login part)?
BTW, I have searched the forums first. Also, the session handlers are working properly. I added this code after I made sure of that.
Thanks very much,
Pras