#login.phpdefine('SESSION_LIFE',1800);session_set_cookie_params(SESSION_LIFE);
session_start();
$_SESSION['cookie'] = $user;
//打印session 参数
echo session_id().'<br>';
$arr = session_get_cookie_params();
print_r($arr);----------------------------------------------------------------------------
55db8cbe4b2c5cafe6de3049a5887ff3
Array ( [lifetime] => 1800 [path] => / [domain] => [secure] => [httponly] => )
--------------------------------------------------------#index.php//打印session 参数
echo session_id().'<br>';
$arr = session_get_cookie_params();
print_r($arr);55db8cbe4b2c5cafe6de3049a5887ff3
Array ( [lifetime] => 0 [path] => / [domain] => [secure] => [httponly] => ) -----------------------------------------------------------------------------#PHP.INI[Session]
; Handler used to store/retrieve data.
session.save_handler = filessession.use_cookies = 1;session.cookie_secure =; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1; Name of the session (used as cookie name).
session.name = PHPSESSID; Initialize session on request startup.
session.auto_start = 0; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0; The path for which the cookie is valid.
session.cookie_path = /; The domain for which the cookie is valid.
session.cookie_domain =; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
session.cookie_httponly =session.gc_probability = 1
session.gc_divisor = 100; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
session_start();
$_SESSION['cookie'] = $user;
//打印session 参数
echo session_id().'<br>';
$arr = session_get_cookie_params();
print_r($arr);----------------------------------------------------------------------------
55db8cbe4b2c5cafe6de3049a5887ff3
Array ( [lifetime] => 1800 [path] => / [domain] => [secure] => [httponly] => )
--------------------------------------------------------#index.php//打印session 参数
echo session_id().'<br>';
$arr = session_get_cookie_params();
print_r($arr);55db8cbe4b2c5cafe6de3049a5887ff3
Array ( [lifetime] => 0 [path] => / [domain] => [secure] => [httponly] => ) -----------------------------------------------------------------------------#PHP.INI[Session]
; Handler used to store/retrieve data.
session.save_handler = filessession.use_cookies = 1;session.cookie_secure =; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1; Name of the session (used as cookie name).
session.name = PHPSESSID; Initialize session on request startup.
session.auto_start = 0; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0; The path for which the cookie is valid.
session.cookie_path = /; The domain for which the cookie is valid.
session.cookie_domain =; Whether or not to add the httpOnly flag to the cookie, which makes it inaccessible to browser scripting languages such as JavaScript.
session.cookie_httponly =session.gc_probability = 1
session.gc_divisor = 100; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440
session.gc_probability = 1
session.gc_divisor = 100
[/code]
你要理解这两行的意思。
因为效率关系,PHP不会每次都去扫描SESSION是否过期,而是采用一个概率去决定,这两个参数设置,这个概率为1/100(百分之一)
session.gc_probability 设置成100 那就能删除了