我已经设置了20分钟的会话超时时间,如下所示。有时会话超时在两到三分钟内发生。
ini_set('session.gc_maxlifetime', 1200);
ini_set('session.cookie_lifetime', 1200);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
可能存在什么问题?
我已经设置了20分钟的会话超时时间,如下所示。有时会话超时在两到三分钟内发生。
ini_set('session.gc_maxlifetime', 1200);
ini_set('session.cookie_lifetime', 1200);
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 100);
更好的做法是将As PHP's Session Control does not handle session lifetimes correctly when using session_set_cookie_params(), we need to do something in order to change the session expiry time every time the user visits our site. So, here's the problem.
$lifetime=600; session_set_cookie_params($lifetime); session_start();
This code doesn't change the lifetime of the session when the user gets back at our site or refreshes the page. The session WILL expire after $lifetime seconds, no matter how many times the user requests the page. So we just overwrite the session cookie as follows:
$lifetime=600; session_start(); setcookie(session_name(),session_id(),time()+$lifetime);
And now we have the same session cookie with the lifetime set to the proper value.
session.cookie_lifetime
设置为0
,这样当浏览器关闭时,cookie会过期。否则,用户可能会认为关闭浏览器会结束他们的会话,但在20分钟超时之前重新打开浏览器时,他们会感到惊讶。1/1
表示PHP将在每个session_start
调用时检查会话文件的日期。1/100
意味着PHP将随机检查会话文件的日期,但大约每100个session_start
调用一次。ini_set
设置session.cookie_lifetime
,这与使用session_set_cookie_params
相同。 - Salman A
ini_get()
函数返回什么? - Mihai Iorga