How to create "remember me checkbox" using Codeigniter session library?

Viewed 45046

in Codeigniter I am building an Authentication system for my web site and to achieve that I use session library

     session->set_userdata('username')

this will save the session -I believe- for some time

I want to provide a "remember me" checkbox in the login form so the user can save the session forever - could not find a way to save the session forever!?

Note:$sess_expiration will not work because it sets expiration date for all users and what I want to do is setting the expiration date based on his preferences

is that possible? and how to do it?

Thanks

7 Answers

You can just put this

if ($remember) {

  $new_expiration = (60*60*24*365);

  $this->config->set_item('sess_expiration', $new_expiration);

  $this->config->set_item('sess_expire_on_close', FALSE);

  $this->session->sess_expiration = $new_expiration;

  $this->session->sess_expire_on_close = FALSE;

}
Related