ThinkPHP6.0 Session类使用方式
要使用Session类必须使用门面方式( think\facade\Session )调用
新版本不支持操作原生$_SESSION数组和所有session_开头的函数,只能通过Session类(或者助手函数)来操作
1、配置文件 session.php
return [
// session name
'name' => 'PHPSESSID',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// 驱动方式 支持file cache
'type' => 'file',
// 存储连接标识 当type使用cache的时候有效
'store' => null,
// 过期时间
'expire' => 1440,
// 前缀
'prefix' => '',
];
2、开启Session
中间件 app\middleware.php 文件
\think\middleware\SessionInit::class
3、设置
session 支持多级数组操作
Session::set('name','www.hezhidz.com');
// Session数组
Session::set('admin.name','欧阳克');
Session::set('admin.uid',1);
4、读取
// 获取全部Session
Session::all();
// 获取Session中name的值
Session::get('name');
5、删除
Session::delete('name');
6、取值并删除
Session::pull('name');