89

Do PHP sessions timeout by default - ie without any coding on my part would a user eventually be "logged out" after some time of inactivity?

2
  • 1
    Thanks for all those. I wanted a little more straight forward answer hence the question! - upvoted Commented Mar 28, 2012 at 9:06
  • 7
    Amusing how all the answers mention "20 minutes" and "1440 seconds" and no one bothered to notice that 1440 seconds is in fact 24 minutes. Commented Jul 9, 2012 at 8:55

6 Answers 6

139

It depends on the server configuration or the relevant directives session.gc_maxlifetime in php.ini.

Typically the default is 24 minutes (1440 seconds), but your webhost may have altered the default to something else.

Sign up to request clarification or add additional context in comments.

3 Comments

Would like to know why 1440 sec are default? ... stackoverflow.com/a/37176824/57091
Is it 1440 seconds after creation or after last activity ?
switch to 10800 (3h), connect, no activity during more than 2 hours, then test with click a link… it works
20

You can change it in you php-configuration on your webserver. Search in php.ini for

session.gc_maxlifetime() The value is set in Seconds.

Comments

12

Yes, that's usually happens after 1440s (24 minutes)

1 Comment

@Mani When is 1440 seconds 20 minutes?
6

http://php.net/session.gc-maxlifetime

session.gc_maxlifetime = 1440
(1440 seconds = 24 minutes)

Comments

6

You can set the session time out in php.ini. The default value is 1440 seconds

session.gc_maxlifetime = 1440

; NOTE: If you are using the subdirectory option for storing session files
;       (see session.save_path above), then garbage collection does *not*
;       happen automatically.  You will need to do your own garbage
;       collection through a shell script, cron entry, or some other method.
;       For example, the following script would is the equivalent of
;       setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
;          find /path/to/sessions -cmin +24 -type f | xargs rm

Comments

5

Yes typically, a session will end after 20 minutes in PHP.

3 Comments

Do you mean 20 minutes of inactivity ?? or even if the user is active and keeping some sort of requests tot he site will the session expire ?
@rammanoj 20 minutes of inactivity.
1440 seconds is the default which is actually 24 minutes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.