Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend framework session expires prematurely

I'm using Zend Framework for PHP and handling sessions with the Zend_Session module. This is what I have in my Initializer (or bootstrap):

Zend_Session::start();
Zend_Session::rememberMe(864000);

864000 seconds should be good for 10 days, but I'm still being kicked out at about an hour (or maybe a little less). I've tested to see if this statement works at all by setting it to 10 seconds, and indeed I am kicked out at the appropriate time, but when I set it to a very high value, it doesn't work! I went through some of the documentation here: http://framework.zend.com/manual/en/zend.session.html

Another method I saw was to use the following:

$authSession = new Zend_Session_Namespace('Zend_Auth'); 
$authSession->setExpirationSeconds(3600); 

Now, I have different namespaces. Does this mean I have to set this for all of them if I want to keep them from expiring? I haven't tested this method of setting the expiration, but I really wanted to see what the gurus on here had to say about what the correct way of approaching this problem is. Thanks a lot guys...

Also, does anyone know how I can make it so that the session never expires? I've tried setting the second to 0 and -1, but that throws an error.

like image 811
Ali Avatar asked Sep 28 '09 23:09

Ali


2 Answers

I had the same problem and solved it by putting:

resources.session.save_path = APPLICATION_PATH "/../data/session/"
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000

in the application.ini (as suggested by tawfekov) and

protected function _initSessions() {
    $this->bootstrap('session');
}

in the Bootstrap.php (this I typically forgot at first). You have to give the session directory the correct access rights (chmod 777). I described the issue here. Hopefully this will help the next person with the same issue.

like image 78
Jasper Avatar answered Dec 04 '22 10:12

Jasper


Your client's computer clock, date, AND time zone need to be set correctly for session expirations to work. Otherwise the time conversions are off, and likely causing your cookie to expire the minute it hits the their browser.

like image 39
Shimon Amit Avatar answered Dec 04 '22 12:12

Shimon Amit