Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP session timeout

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?

like image 510
user398341 Avatar asked May 20 '11 17:05

user398341


People also ask

How long is PHP session timeout?

gc_maxlifetime and session. The superglobal variable $_COOKIE array has been used here to handle the session. The new session will be generated for the user when the script will execute in the browser and after two seconds the session will be expired.

Can we set time for session in PHP?

Session timeout can be customized, to make the user's page inactive after a fixed time. Starting session: The PHP, session_start() function is used to start a session in the web page.

What is the default timeout for any PHP session?

Defaults to 1440 (24 minutes). Note: If different scripts have different values of session. gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data.


1 Answers

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
like image 114
user398341 Avatar answered Oct 19 '22 20:10

user398341