当前位置:网站首页>laravel 写api接口时 session获取不到处理办法
laravel 写api接口时 session获取不到处理办法
2022-08-02 03:26:00 【陌潇】
在写接口时,同一个控制器里session可以随意获取可以用,但是跨方法就获取不到了,怎么回事呢?
修改app/Http/Kernel.php文件即可
一、解决办法
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Session\Middleware\StartSession::class,
],
];

把web中的StartSession中间件复制到api中,这就行了。问题就这样简单的解决了。
二、使用方法:

注意一点的是session的键不能是 int 类型,简单点就是不能数出数字,写了纯数字是读取不到你的这个值的。
边栏推荐
- PHP realizes the automatic reverse search prompt of the search box
- PHP反序列化漏洞
- The focus of the Dom implementation input triggers
- 动力:2 vulnhub预排
- (2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets
- hackmyvm-hopper预排
- 学IT,找工作——移除链表元素
- 一个网络安全小白鼠的学习之路——nmap的基本使用
- The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)
- 考(重点理解哪些属于其他货币资金)、其他货币资金的内容、其他货币资金的账务处理(银行汇票存款、银行本票存款、信用卡存款、信用证保证金存款、存出投资款、外埠存款)
猜你喜欢

The learning path of a network security mouse - the basic use of nmap

3000字入门图神经网络

A network security guinea pig's learning path - scripting of advanced usage of nmap

2021-09-04 最简单的Golang定时器应用以及最简单的协程入门儿

【一句话攻略】彻底理解JS中的回调(Callback)函数

hackmyvm-random walkthrough

The CTF introductory notes of SQL injection
![[sebastian/diff] A historical change extension library for comparing two texts](/img/c7/ea79db7a5003523ece7cf4f39e4987.png)
[sebastian/diff] A historical change extension library for comparing two texts

重点考:从债劵的角度来看交易性金融资产

PHP deserialization vulnerability
随机推荐
hackmyvm: may walkthrough
(5) Modules and packages, encoding formats, file operations, directory operations
cmake安装到指定目录
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
一次代码审计的笔记(CVE-2018-12613 phpmyadmin文件包含漏洞)
A network security guinea pig's learning path - scripting of advanced usage of nmap
Pycharm packages the project as an exe file
CTF入门笔记之ping
一个网络安全小白鼠的学习之路——nmap的基本使用
[sebastian/diff] A historical change extension library for comparing two texts
Offensive and defensive world - novice MISC area 1-12
文件上传漏洞
web安全之目录遍历
2021-09-04 最简单的Golang定时器应用以及最简单的协程入门儿
PHP realizes the automatic reverse search prompt of the search box
DNS详解
C language uses stack to calculate infix expressions
CTF入门之md5
敏感信息泄露
The CTF introductory notes of SQL injection