Reputation: 772
How to keep CakePHP 1.3 session after browser is closed?
Upvotes: 1
Views: 1591
Reputation: 3088
Seems there are ways to increase the time for the session to live on through an overridden configuration value. (At the PHP level -- via CakePHP Manual). Using the code below you could change 0 to the number of seconds you'd like the session to live on for.
// Cookie is now destroyed when browser is closed, doesn't
// persist for days as it does by default for security
// low and medium
ini_set('session.cookie_lifetime', 0);
Example for 2 weeks:
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 14);
The above code snippet would be written to a configuration file that you create in app/config
. To get CakePHP to read that file on initialization add the following to app/config/core.php
Configure::write('Session.save','my_session');
Where my_session
is the name of your configuration file.
Upvotes: 2
Reputation: 1821
Set $this->Session->cookieLifeTime = $timeToLive;
, where $timeToLive
is the length in seconds you would like the session to last. This is the total length, so if the browser window closes it will not be deleted, but note that it is not measured from the time the browser closed.
Upvotes: 1