Session在用户关闭浏览器时都会清除,在PHP中也可以通过设置session过期时间来自动清除。两个途径:

1. 在php.ini中设置session.gc_maxlifetime:

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
; http://php.net/session.gc-maxlifetime
session.gc_maxlifetime = 1440

2. 在代码中设置:

ini_set('session.gc_maxlifetime','1440');