views:

40

answers:

1

I have been having this problem for some time now, I dont exactly know that if this is the issue but I am pretty confident that it is, I have my remember me session set too expire after 1 week, but when I go to my site after a few hours of inactivity my remember me session is gone, i check my servers tmp dir and the session flat file is gone, what i think is happening is some PHP session garbage collector runs every now and then, but i dont want it to delete these sessions that are suppoes to be stored for a week, how do a modify this behavior?

+2  A: 

You're confusing two things.

  • A "remember me" mechanism doesn't rely on sessions. It relies on a cookie that stores credentials which are used to start a session. In this case, you have to setup the cookie so that is last for one week. See this answer.
  • If you just want to extend the lifetime of sessions, you have to both extend the lifetime of the session cookie to one week and delay garbage collection. This is done changing session.gc_maxlifetime.
Artefacto
[Here's a pretty good previous question about "Remember Me"](http://stackoverflow.com/questions/1354999/keep-me-logged-in-the-best-approach) and how to implement it well as a separate cookie.
Charles
Ok so if thats the case, then I can see the cookie that php set, it says it will expire at a date that is after 7 days, but even if the session cookies exists, why is it not initializing the session again, i mean i have a cookie and it will stay there for the next 7 days, but when i visit the site with that cookie I am still taken to login, .. any thoughts?
Akay
@Charles,Oh hi thanks for helping out again, your last explanation was quite an eye opener
Akay
@Akay If that cookie is the session cookie set by PHP with `session_start`/`session_set_cookie_params`, the existence of the cookie itself is not enough if PHP then deletes the data associated with the session via garbage collection. If the cookie is actually a remember me cookie you have to manually read the cookie and use its data to authenticate the user in a new session.
Artefacto
OH ok ok, so thats the story, thats cool i guess i can solve this problem now, thanks for your help@Charles, i checked out the link, i found it quite helpful
Akay