The default time for a PHP session is 1440 seconds (24 minutes). After that, the session data is eligible for garbage collection and the user may need to log in again.

You can change it by doing the following:

ini_set("session.gc_maxlifetime", 1440);

You can obviously adjust the second parameter (1440) to anything you like to change the timeout limit.

Keep in mind that gc_maxlifetime sets the minimum time before a session can be cleaned up — it’s not a hard expiry. PHP’s garbage collector runs probabilistically, so sessions might live a bit longer than this value. If you need precise session expiry, store a timestamp in the session itself and check it on each request.

Also, if you’re on shared hosting, other sites’ PHP scripts might trigger garbage collection with a shorter gc_maxlifetime, which could clean up your sessions early. In that case, consider using a custom session save path with session_save_path().