Laravel Request Cookie不显示JS创建的Cookie [英] Laravel Request cookie doesn't show JS created Cookies
问题描述
我正在使用 JS-Cookie 通过前端设置Cookie,结尾.为什么我不能通过以下方式在Laravel 5.8应用程序中访问它: dd(request()-> cookies)
?Cookie 随名称可见,但值为空.但是,当我尝试通过正常"方式获取Cookie的值时,我的确得到了值: dd($ _ COOKIE ['the-cookie-value-i-want']);
.
I'm using JS-Cookie for setting a Cookie via the front-end.
Why can't I access it in my Laravel 5.8 application with:
dd(request()->cookies)
? The Cookie is visible with the name, but the value is null. But when I do try to get the Value of the Cookie via the "normal" way, I do get the value: dd($_COOKIE['the-cookie-value-i-want']);
.
如何通过"Laravel-way"访问Cookie的值?哪个更安全.
How can I access the value of the Cookie via the "Laravel-way"? Which is more secure.
推荐答案
我知道这是一个老问题,但是您可以禁用特定Cookie的加密,而不是对所有Cookie都禁用(这会破坏安全会话).
I know this is an old question, but you can disable encryption for specific cookies instead of disabling it for everything (which would break secure sessions).
编辑 \ App \ Http \ Middleware \ EncryptCookies
类以包括以下内容:
Edit the \App\Http\Middleware\EncryptCookies
class to include the following:
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
'my_frontend_cookie_name'
];
您现在可以通过 request()-> cookie()
或 Cookie :: get()
门面访问cookie值.
You can now access the cookie value via request()->cookie()
or the Cookie::get()
facade.
这篇关于Laravel Request Cookie不显示JS创建的Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!