How to make user session go on for 24 hours?
I have messed around with my apache and php.ini file and my site's users still complain开发者_C百科 about the site logging them out after a very short time or every time they close and open the same browser.
I am running Apache and PHP.
What settings should I have in order to make the users session go for 24 hours so they don't have to re-log in every time?
Thanks, Alex
In php.ini, set:
; 24 hour session cookie
session.cookie_lifetime = 86400
; Prevent server from cleaning up session
; Some value higher than the cookie lifetime
session.gc_maxlifetime = 200000
Strange. Sessions should stay for quite a long time. Try checking your code for any accidental session_destroy()s.
If that doesn't work, then maybe try using cookies:
setcookie(name, value, expire);
So, to set a cookie variable in PHP, you would simple use
<?php
setcookie("MyCookie", "MyValue", time()+60*60*24);
?>
The expire value is in seconds. Using the code above, you would be able to set a cookie called "MyCookie" with the value "MyValue" and lasts for 24 hours.
To retrieve the value of this cookie, you could use
<?php
print($_COOKIE['MyValue']);
?>
Note that cookies MUST be set before the tag is called.
If cookies don't work either, then it's probably a problem with your php.ini Can you post your php.ini if cookies don't work?
Hope this helps!
精彩评论