CodeIgniter Forums
Extending Session timeout - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Extending Session timeout (/thread-22244.html)



Extending Session timeout - El Forum - 09-02-2009

[eluser]coding_hero[/eluser]
I'm trying to extend the session timeout ala this thread. Here's my code snippet from the login routine ('remember' is a check box on the login page):

Code:
// Remember for one week.
if ($this->CI->input->post('remember') =="checked")
{
    $this->CI->config->set_item('sess_expiration', 60*60*24*7);
}

The problem I'm having is that every time thereafter that CI_Session is called, the following code gets called (line 170, Session.php):

Code:
// Is the session current?
if (($session['last_activity'] + $this->sess_expiration) < $this->now)
{
    $this->sess_destroy();
    return FALSE;
}

Since '$this->sess_expiration' is set back to the value in the config file every time that CI_Session is instantiated, I'm not sure how the code in the other thread was supposed to work. Has anyone been able to extend the timeout based on a condition like the above? What's the best way to do it without re-writing large chunks of the Session class?

Thanks!


Extending Session timeout - El Forum - 09-03-2009

[eluser]bretticus[/eluser]
I'd probably not use sessions at all in this instance. I'd set a cookie with an encrypted string that identifies the user. If that cookie is encountered, I'd setup a session for them.

Yes, a little "hacky" but at least you're not hacking up session core code.