当前位置:网站首页>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 类型,简单点就是不能数出数字,写了纯数字是读取不到你的这个值的。
边栏推荐
- The first time to tear the code by hand, how to solve the problem of full arrangement
- Anaconda报错:An unexpected error has occurred. Conda has prepared the above report 解决办法
- CSRF (Cross Site Request Forgery)
- 什么是广告电商商业模式?这几个门派告诉你
- Command Execution Vulnerability
- hackmyvm-bunny walkthrough
- Pycharm packages the project as an exe file
- CTF entry md5
- CSRF(跨站请求伪造)
- Mysql创建索引
猜你喜欢

Offensive and defensive world - novice MISC area 1-12

(2) Sequence structures, Boolean values of objects, selection structures, loop structures, lists, dictionaries, tuples, sets

File upload vulnerability

管理会计(对内)指引、管理会计要素及其具体内容(可能考,考前记一下,推荐记一下四个大点即可)、

The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)

强化学习笔记:DDPG

会计凭证概述、原始凭证、原始凭证的种类、原始凭证的基本内容、原始凭证的填制要求、原始凭证的审核

Phonebook

广告电商「私域打工人」职业前景:你离月薪6万,还差多远?

hackmyvm-random walkthrough
随机推荐
PALISADE:CKKS的使用
借贷记账法下的账户结构、借贷记账法的记账规则、借贷记账法下的账户对应关系与会计分录
Uniapp | compatibility problems in the development of (to be continued)
一个网络安全小白鼠的学习之路——nmap的基本使用
(3) string
Introduction to PHP (self-study notes)
DarkHole: 2 vulnhub walkthrough
web安全之目录遍历
OPENSSL基本实验以及OPENSSL详解
利用cookie获取admin权限 CTF基础题
How to determine the direction based on two coordinate points on the map
PHP deserialization vulnerability
hackmyvm: kitty walkthrough
redis未授权访问(4-unacc)
hackmyvm: may walkthrough
PHP Foundation March Press Announcement Released
二舅为什么能刷屏?这三件事对企业公关的启示
What are the killer super powerful frameworks or libraries or applications for PHP?
最简单的FRP内网穿透教程
web渗透必玩的靶场——DVWA靶场 1(centos8.2+phpstudy安装环境)