Why PHP session is deleted on page reload?

2019-02-27 19:51发布

问题:

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.

回答1:

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