开发者

CodeIgniter extend user's session expiration time

开发者 https://www.devze.com 2022-12-25 22:41 出处:网络
Is it possible to extend user\'s session expiration time in CI. What I want to开发者_StackOverflow do is, by default every user\'s session cookie lasts for example 1 day, but every time user visits th

Is it possible to extend user's session expiration time in CI. What I want to开发者_StackOverflow do is, by default every user's session cookie lasts for example 1 day, but every time user visits the site his session expiration time is extended by one more day.

I don't know if it is a good idea to do this, maybe I should just set cookies life time for like a week and that's it?


I believe what you want is actually the default behavior. Take a look at sess_read() and sess_update() in /system/libraries/Session.php

last_activity for an active session is updated every five minutes.

Session expiration is checked with last_activity + sess_expiration < now

So, for the behavior you want, just set your sess_expiration time to 86400 (one day), and you should be all set.


From the User Guide:

$sess_expiration: The number of seconds you would like the session to last. The default value is 2 hours (7200 seconds). If you would like a non-expiring session set the value to zero: 0

Hopefully this is what you're wanting to do?


Are you talking about the Session component in CodeIgniter? You can go to config.php and set $sess_expiration = 7200; (7200 is the default)

http://codeigniter.com/user_guide/libraries/sessions.html


Default session time in codeigniter is

$sess_expiration = 7200; // This is 2 hours

Also you can set $sess_expiration = 0; This means you are setting session for forever.

Actually I could see in codeigniter library Session.php

// Set the session length. If the session expiration is
// set to zero we'll set the expiration two years from now.
if ($this->sess_expiration == 0)
{
     $this->sess_expiration = (60*60*24*365*2);
}


You can use this:

$this->config->set_item('sess_expiration', $sec);
$this->session->sess_destroy();
$this->session = new CI_Session();
// where $sec is the seconds until expiration


Go to Application->config.php

CodeIgniter extend user's session expiration time

For one day: 86400 For week : 604800

0

精彩评论

暂无评论...
验证码 换一张
取 消