#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

解决方案 »

  1.   

    现在的问题是Session 一直有效,直到关闭浏览器或退出为止,设置的生存时间不起作用啊
      

  2.   

    [code=INIFile]
    session.gc_probability = 1
    session.gc_divisor    = 100 
    [/code]
    你要理解这两行的意思。
    因为效率关系,PHP不会每次都去扫描SESSION是否过期,而是采用一个概率去决定,这两个参数设置,这个概率为1/100(百分之一)
      

  3.   

    3L说得对。"无效"只不过类似给session文件夹一个标记证明他无效了,但是不一定会删除。是有几率的,如果你把
    session.gc_probability 设置成100 那就能删除了