1.全局设置session过期时间:
在配置文件session.php设置过期时间如下 ‘expire’=>60,//过期时间为1分钟
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
return [
'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// SESSION 前缀
'prefix' => 'think',
// 驱动方式 支持redis memcache memcached
'type' => '',
// 是否自动开启 SESSION
'auto_start' => true,
//过期时间 单位秒
'expire'=>60,//过期时间
];
如上设置好了,session变量就是在规定时间内被销毁,而且是全局变量,所有的session变量都会按照这个规则,有过期时间。