PHP setcookie 是否支持设置 SameSite

2019-11-30 13:39:51 +08:00
 7DLNU56W

现在 setcookie Header 里面多了一个 SameSite,但 php 里的 setcookie 怎么设置这个值呢?

6257 次点击
所在节点    HTTP
4 条回复
qiayue
2019-11-30 13:44:47 +08:00
littleylv
2019-11-30 13:48:08 +08:00
https://www.php.net/manual/en/function.setcookie.php
7.3.0 开始支持,详情看手册

PS:遇事不决先查手册,查不到再问
7DLNU56W
2019-11-30 15:51:22 +08:00
是说开始支持了,但没说怎么用啊,在最上面使用的语法那里,根本没有 SameSite 选项。
littleylv
2019-11-30 16:29:34 +08:00
@7DLNU56W #2 你不会浏览器 control+F 搜索一下“ SameSite”?

setcookie ( string $name [, string $value = "" [, int $expires = 0 [, string $path = "" [, string $domain = "" [, bool $secure = FALSE [, bool $httponly = FALSE ]]]]]] ) : bool
setcookie ( string $name [, string $value = "" [, array $options = [] ]] ) : bool

options
An associative array which may have any of the keys expires, path, domain, secure, httponly and samesite. The values have the same meaning as described for the parameters with the same name. The value of the samesite element should be either Lax or Strict. If any of the allowed options are not given, their default values are the same as the default values of the explicit parameters. If the samesite element is omitted, no SameSite cookie attribute is set.


那当然是
setcookie('key', 'val', [
'domain' => 'xx',
'expires' => 'yy',
'samesite' => 'Lax',
]);

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/624572

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX