views:

237

answers:

3

Hi,

Is it possible to extend user's session expiration time in CI. What I want to 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?

Thanks!

A: 

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

Ivo Sabev
The way I understand $sess_expiration just tells how long session cookie lives since it was created, 2 hours in this case, what I want to achieve is if user is active, his session cookie theoretically does not expire. I hope this makes more clear...
spacemonkey
A: 

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?

Andy Copley
A: 

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.

Billiam
You should be setting it in the config.php file not in the actual library file. When you upgrade the codeigniter core you will lose the changes.
Tom Schlick
For the record, I meant take a look at the system file to see how Codeigniter's sessions work as relates to the original question, not to make any changes there, but I can see how that may have been unclear.
Billiam

related questions