0

I'm saving the user language choice into the sessions like this:

$this->session->set_userdata('language', $language);

And then I'm setting the language depending on the session data (and making a English , as a default language).

if ( !$language = $CI->session->userdata('language') )
{
    $language = "english";
}

$CI->config->set_item('language', $language);

It works good, but the language that user has chosed lasts only for approx. 2 hours - then user have to pick the language again. So the question is, how can I extend the session time to expire (or make it expire only in case if user cleans up the browser data). I can not save the user choice in the database, because I need to also handle guests on my website.

I know I can extend the session time in the CI's config, but I just want it to happend only in case of the language selection, and not for example for accounts sessions.

Cyclone
  • 14,839
  • 23
  • 82
  • 114

1 Answers1

1

It is the same session, and it either expires or doesn't. You can't have the authentication part expire, but not the language selection. CI doesn't make it easy to manage multiple sessions, which would have made it possible to store authentication in one short-lived session and language preference in a longer-lived one. As it is, it might be easier to just store language preference directly in a cookie; just keep in mind that you will have to set the cookie again on each request, otherwise it will not get refreshed automatically upon user activity and will expire even if the user is actively using the site.

lanzz
  • 42,060
  • 10
  • 89
  • 98
  • I was thinking about the cookies also, but wasn't sure if it's good for this purpose. Seems like its the only way now. – Cyclone Jun 02 '12 at 22:22
  • Well you could also implement an entire secondary session yourself, but seems like an overkill to me. A cookie fits this purpose well. – lanzz Jun 02 '12 at 22:27