PHP session timeout
Asked Answered
S

3

5

Can someone explain exactly how to make the session to last for longer in PHP, but without using php.ini?

I've tried the following in .htaccess:

<IfModule mod_php5.c>
    #Session timeout
    php_value session.cookie_lifetime 3600
    php_value session.gc_maxlifetime 3600
</IfModule>

I've also tried:

ini_set('session.gc_maxlifetime', '3600');

But none of them seem to be working.

Any idea?

Shareeshareholder answered 20/5, 2011 at 17:49 Comment(4)
are you sure with '3600'? i mean there you are using quote, have you try if ini_set('session.gc_maxlifetime', 3600); ??? (without single quotation near 3600)Mikemikel
Longer than what? With your currently configuration, your session should last one hour.Clino
Yes - with the code which I've typed above - which also doesn't work. I simply want to increase to whatever length is required...Shareeshareholder
Also - single quotes don't change anything...Shareeshareholder
S
8

Ok - I've found the way and it works - in the .htaccess I simply added the following to increase the timeout to 5 hours:

php_value session.cookie_lifetime 18000
php_value session.gc_maxlifetime 18000
Shareeshareholder answered 5/6, 2011 at 12:1 Comment(0)
P
7

On many shared hosts all sessions are stored in the same location. Because of the way garbage collection works, this means everyone's sessions get deleted after the shortest GC interval.

One solution is to do:

php_value session.save_path "/my/personal/path"
php_value session.gc_maxlifetime "3600"

Alternatively you can set a custom session save handler. Try changing your save path first, because custom handlers are a bit trickier.

Pau answered 20/5, 2011 at 17:56 Comment(0)
F
0

In conjunction with php-fpm you can use .user.ini instead of the .htaccess file in the directory (works recursive like the .htaccess file).

session.cookie_lifetime=18000
session.gc_maxlifetime=18000

See this to find out when the values gets applied if you change them.

Fortuitous answered 20/12, 2019 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.