laravel 在 cookie 中将 httponly 属性设置为 false

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21510810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:57:34  来源:igfitidea点击:

Setting the httponly property to false in a cookie

phplaravel

提问by Sam Pettersson

How would i using Laravel make a cookie using Cookie::Make(Or something else) and set the httponly property to false?

我将如何使用 Laravel 使用Cookie::Make(或其他方式)制作 cookie并将 httponly 属性设置为 false?

I would want to do this as the cookie contains a key which my JS must be able to read.

我想这样做,因为 cookie 包含一个我的 JS 必须能够读取的密钥。

回答by Chris G

Laravel provides an option for this, but the docs don't show it. The best way is to look through the source. If you take a look at the CookieJar.php file hereyou'll see the httpOnly option.

Laravel 为此提供了一个选项,但文档没有显示它。最好的方法是查看源代码。如果您在此处查看CookieJar.php 文件您将看到 httpOnly 选项。

public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)

so simply do something like:

所以只需执行以下操作:

Cookie::make('MyCookie', 'MyValue', 60, null, null, false, false);