1

So I've this problem that, when I'm on the page not doing anything for some time, after I reload the page $_SESSION is cleared. I checked the code and it does not have any unset() functions or anything else what could clear the $_SESSION variable. Any ideas why is it happening?

Edit: In case if I want to make the session live till the browser is closed what should I do? I don't understand it as the gc checks if session is expired on session_start, but I can't modify the session data before calling session_start, so modifying the session data after calling session_start would result in expired session anyway?

I've the session.cookie_lifetime set to 0 by default, session.gc_maxlifetime, session.gc_divisor, session.gc_probability are set to their default values too.

Farshid Shekari
  • 2,391
  • 4
  • 27
  • 47
Rihards
  • 10,241
  • 14
  • 58
  • 78
  • What value is *session.gc\_maxlifetime* and did you *understand* [my post on how PHP’s session expiration model works](http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes/1270960#1270960)? – Gumbo Feb 03 '11 at 18:51
  • @Gumbo, *session.gc_maxlifetime* is set to default 1440. I think I did, yes. I've *session.gc_probability* and *session.gc_divisor* set those to default values too. – Rihards Feb 03 '11 at 19:59
  • 1
    @Richards: And this vague idle time aren’t these 1440 seconds? Remember that PHP’s default garbage collector calculates the age based on the session file’s modification time. – Gumbo Feb 03 '11 at 22:20
  • @Gumbo, but my question is: how to reset the garbage collector timer for the session so it doesn't erase the session? I'm not understanding it cause, the garbage collector does it's job when the *session_start()* is called, but I can't modify the session data before calling the *session_start()*. – Rihards Feb 03 '11 at 22:45
  • @Richards: You can’t reset it because there is no timer. It’s the age of the session data (i.e. the time of its last modification) that constitutes in combination with the *session.gc\_maxlifetime* value whether a session is expired. The garbage collector is just the routine that deletes such sessions. And when that happens the session *is* already expired. – Gumbo Feb 03 '11 at 22:58
  • @Gumbo, so to fix this problem I just have to increase the session.gc_maxlifetime to bigger one? – Rihards Feb 09 '11 at 18:13
  • @Gumbo, what would be safe lifetime? I mean not to overload stuff and so on? What do you have it set to? – Rihards Feb 09 '11 at 18:27
  • @Richards: That depends on the purpose of your session. So what do you need it for and what would be the consequences of a premature expiry? – Gumbo Feb 09 '11 at 20:49

1 Answers1

5

Have you put de session_start() at the beginning of every page?

raultm
  • 706
  • 6
  • 20