使用Laravel Cookie和纯PHP $ _COOKIE之间的区别? [英] Difference between using Laravel Cookie and plain php $_COOKIE?

查看:92
本文介绍了使用Laravel Cookie和纯PHP $ _COOKIE之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript设置了一个cookie,并且尝试使用laravel PHP在后端进行读取.当我尝试运行其中任何一个时,都会得到null:

I set a cookie with javascript and I'm trying to read on the backend with laravel PHP.. When I try running either of these, I get null:

Cookie::get('locale');
$locale = $request->cookie('locale');

现在,当我运行普通的旧php版本时,可以正常获取cookie.

Now when I run the plain old php version, I get the cookie normally.

$_COOKIE['locale'];

有什么区别?为什么在使用laravel版本时我会得到null?

What's the difference? Why do I get null when using the laravel version?

推荐答案

这是因为laravel cookie加密.您只能不包含EncryptCookies中间件,以避免出现此问题.从app\Http\Kernel.php

It's because of laravel cookie encrypting. You can just not include EncryptCookies middleware to avoid this problem. Remove \App\Http\Middleware\EncryptCookies::class from $middlewareGroups in app\Http\Kernel.php

这篇关于使用Laravel Cookie和纯PHP $ _COOKIE之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆