Skip to content
Advertisement

How long php sessions are stored in server?

I’m wondering how long php sessions are stored in server memory.What if user logs in (sets session variables in server) and he keeps his browser open for a long time suppose 30 days and he reloads the page on the 31st day? Can browser access session variables(browser still has session cookie)?

Advertisement

Answer

Default php.ini sets the session expiration time to 30 minutes.

Check out these settings: session.gc_maxlifetime and session.cookie_lifetime

As long as the browser have the cookie stored, it doesn’t matter if it is closed or is open.

If you want to store the session for lets say 30 days, you can add:

ini_set('session.gc_maxlifetime', 30*24*60*60);
ini_set('session.cookie_lifetime', 30*24*60*60);
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement