82

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?

KB.
  • 3,419
  • 4
  • 22
  • 28
  • 1
    Thanks for all those. I wanted a little more straight forward answer hence the question! - upvoted – KB. Mar 28 '12 at 09: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. – maligree Jul 09 '12 at 08:55

6 Answers6

136

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.

AbraCadaver
  • 77,023
  • 7
  • 60
  • 83
Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566
18

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.

suther
  • 11,070
  • 2
  • 53
  • 91
11

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

haltabush
  • 4,438
  • 2
  • 23
  • 41
6

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

session.gc_maxlifetime = 1440
(1440 seconds = 24 minutes)
Elangovan
  • 3,349
  • 4
  • 29
  • 37
5

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
rafee_que_
  • 709
  • 8
  • 13
4

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

Jeroen
  • 3,361
  • 1
  • 21
  • 25