我使用JS-Cookie通过前端设置Cookie。为什么我不能在我的Laravel5.8应用程序中使用:dd(request()->cookies)访问它?Cookie使用名称可见,但值为null。但是,当我尝试通过“正常”方式获取Cookie的值时,我确实获得了值:dd($_COOKIE['the-cookie-value-i-want']);。
如何通过"Laravel-way“访问Cookie的价值?哪个更安全。
发布于 2021-03-30 02:41:39
我知道这是一个老问题,但您可以禁用特定cookie的加密,而不是禁用所有内容(这会中断安全会话)。
编辑\App\Http\Middleware\EncryptCookies类以包含以下内容:
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
'my_frontend_cookie_name'
];现在,您可以通过request()->cookie()或Cookie::get()外观访问Cookie值。
发布于 2019-04-25 19:45:33
只有由laravel创建的才能由laravel处理。
下面是你可以实现这一点的方法
进入:app > Http > Kernal.php:在$middlewareGroups数组下注释如下
'web' => [
//\App\Http\Middleware\EncryptCookies::class,然后试一试
这是演示
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
{{ Cookie::get('cookie1') }}
{{ request()->cookie('cookie1') }}
<script type="text/javascript">
document.cookie = 'cookie1=test; path=/'
</script>
</body>
</html>https://stackoverflow.com/questions/55848069
复制相似问题