2

I have added the following lines in my htaccess file :

php_value session.cookie_lifetime 14400
php_value session.gc_maxlifetime 14400

Also have added a php.ini file in the root directory with the following code :

session.gc_maxlifetime = 14400
session.cookie_lifetime = 14400

Also inside the php code have added the following lines :

ini_set('session.cookie_lifetime',14400);
ini_set('session.gc_maxlifetime',14400);
setcookie("_lid", $lid, time() + 14400);

So basically the session should work for 4 hours. But it is getting timed out in about 24 mins or so which is the default timeout time in php.

I may be missing something. Would be great if someone can provide some inputs.

Thanks

Vinay B
  • 63
  • 1
  • 8
  • I cannot yet answer your question in whole, but a php.ini in your web root has no use. php does not use it. it will only use the one in your main configuration folder. – Raphioly-San Jun 24 '14 at 12:27
  • Just curious, why would you set the session lifetime if you only want to set a non-related cookie? What are you trying to accomplish? You can always set a cookie with a greater retention time, no matter what the session time is. – Raphioly-San Jun 24 '14 at 12:34
  • To check the login authorization a session variable is used which is checked and that gets removed after some time even though the cookie is retained. – Vinay B Jun 24 '14 at 13:10
  • Did you ever resolve this? I am having the exact same issue. And I check via phpinfo() and the session.gc_maxlifetime & session.cookie_lifetime are both set to 14400 - It is clearly a) not working as designed or b) using something else to determine session timeout... – php-b-grader Apr 05 '19 at 02:16

1 Answers1

0

I was having the exact same problem - the session.gc_maxlifetime & session.cookie_lifetime values were set but appeared to not be honoured... Then, I found a comment on an old thread which clearly needs a lot more recognition:

How do I expire a PHP session after 30 minutes?

Please note that at least two settings are crucial to setting the session time, and maybe three. The two certainly crucial ones are session.gc_maxlifetime and session.cookie_lifetime (where 0 is not the same as some long number). For complete, 100% certainty of allowing long times, it may also be necessary to set the session.save_path, due to varying OS-controled cleanup time on the /tmp directory where session files get stored by default. – @Kzqai Apr 7 '11 at 8:04

php-b-grader
  • 3,191
  • 11
  • 42
  • 53