Make sessions last until browser closes PHP

Viewed 100

I'm working on cpanel Linux Godaddy hosting, I don't have access to php.ini

I've created .user.ini

Worked fine for changing settings, I have the values and as I upload a change, configuration changes inmediately.

My problem is that sessions won't last, although session.cookie_lifetime=0 and session.gc_maxlifetime=0, they close without closing the browser.

Does other directives have something to do? What's the difference between local and master value, is master value above local? as session.gc_maxlifetime=1440 and set to 0 by me on the .user.ini

phpinfo.php

1 Answers

session.cookie_lifetime tells the client browser how long to keep the cookie around, and a setting of 0 discards the cookie when the browser/tab is closed.

session.gc_maxlifetime tells PHP the maximum possible age of session files when running a cleanup, and a setting of 0 means that any time session GC [probabilistic, see docs] runs all sessions that haven't been touched in longer than 0 seconds will be cleaned up, which is all of them.

You should understand that PHP sessions denote no persistence between the client and the server. A PHP session is just a blob of data identified by a token which is served to the client browser as a cookie, which is then passed back on subsequent requests.

TLDR: Your session.cookie_lifetime setting is fine, but setting session.gc_maxlifetime to zero is causing your issue. Return it to its default value, which is usually a day or two, or determine a value that balances user convenience with whatever reason you want to clean up old session files.

Related