Forum Moderators: coopster
My session settings are as follows (they are placed in a config.php file that is included in scripts)
ini_set( 'session.use_cookies', '1' );
ini_set( 'session.use_only_cookies', '1' );
ini_set( 'session.cookie_lifetime', '0' );
ini_set( 'session.gc_maxlifetime', '7200' );
ini_set( 'session.save_path', SESSIONS_DIR );
(permission for the session_dir are 777)
To handle sessions i have the following functions
function createSession ( )
{
session_start();
if ( isset($_SESSION[ 'auth' ]) ) {
//Session already exists, not created
return false;
}
$_SESSION[ 'auth' ] = 'done';
return true ;
}
function verifySession( )
{
session_start();
if( isset($_SESSION['auth']) && ($_SESSION['auth'] == 'done') ){
return true ;
}
else{
// delete the session created for verification
$_SESSION = array();
if( isset($_COOKIE[session_name()]) ){
setcookie(session_name(),'',time()-42000, '/');
}
session_destroy();
return false ;
}
}
The problem is that the verifySession function keeps returning false in my hosting env. This happens continuously for long periods of time and then stops happening (apparently all by itself).
I observed that the hosting server changed time (moved back) in one such long duration.
I am absolutely clueless about why this could be happening. Any thoughts about what could be causing this? Any suggestions about additions to the session handling code will be appreciated.
Thanks
On shared servers garbage collection from other users running short-life sessions can have the effect of prematurely killing your sessions. The resolution is to use a directory within your webspace to store your sessions date instead.
There's a couple good, simple scripts publicly available through a Google search, or you can write your own using session_set_save_handler (look up in the PHP documentation).