PHP Session Timeout

Can someone explain how to make a session longer in PHP, but without using php.ini?

I 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 also tried:

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

But none of them seem to work.

Any idea?

+5
source share
2 answers

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

php_value session.cookie_lifetime 18000
php_value session.gc_maxlifetime 18000
+8
source

On many shared hosts, all sessions are stored in one place. Due to how garbage collection works, this means that all sessions are deleted after the shortest GC interval.

One solution:

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

. , .

+7

All Articles