thinkphp6 入门(8)-- Session

开启Session

Session功能默认是没有开启的(API应用通常不需要使用Session

复制代码
'think\middleware\SessionInit'

// 添加引用

复制代码
use think\facade\Session;

赋值

复制代码
Session::set('name', 'thinkphp');

取值

复制代码
// 如果值不存在,返回null
Session::get('name');
// 如果值不存在,返回空字符串
Session::get('name', '');
// 获取全部数据
Session::all();

删除

复制代码
Session::delete('name');

取值并删除

复制代码
// 取值并删除
Session::pull('name');

如果name的值不存在,返回Null

清空

复制代码
Session::clear();

原文:Session · ThinkPHP6.0完全开发手册 · 看云ThinkPHP`6.0`基于精简核心和统一用法两大原则在`5.1`的基础上对底层架构做了进一步的优化改进,并更加规范化。 https://www.kancloud.cn/manual/thinkphp6_0/1037635

相关推荐
妙码生花4 天前
全新的 TP8+Workerman+BuildAdmin 整合方案,已有近 2000 次下载使用。
websocket·php·thinkphp
quweiie5 天前
在php8.3下签到、签退打卡的实现
thinkphp·签到·nesbot/carbon
天宁2 个月前
Workerman + ThinkPHP 8 结合使用
php·thinkphp
云游云记2 个月前
ThinkPHP 队列扩展 (topthink/think-queue) 使用笔记
php·thinkphp·think-queue
用户14644605033793 个月前
PHP 多维数组处理利器:array_column() 用法详解
php·thinkphp
用户3074596982073 个月前
ThinkPHP 6.0 多应用模式下的中间件机制详解
后端·thinkphp
行思理3 个月前
小游戏系统提供二开服务
layui·游戏程序·小游戏·thinkphp
xmode4 个月前
常用自定义函数laravel版+thinkphp版
后端·php·laravel·thinkphp
mooyuan天天4 个月前
内网渗透之Thinkphp5提权实战+reGeorg代理横向移动(CVE-2018-20062)
内网渗透·横向移动·thinkphp·regeorg·cve-2018-20062·thinkphp代码执行漏洞
蹦极的考拉4 个月前
夜间无法登录:ThinkPHP api接口 23:00 准时罢工的排查全纪录
小程序·thinkphp·api接口·无法登陆