PHP setcookie“SameSite=Strict"? [英] PHP setcookie "SameSite=Strict"?

查看:50
本文介绍了PHP setcookie“SameSite=Strict"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近阅读了RFC 6265";在属性Same Site"上,我查看了一些在 2016 年 4 月讨论过的文章,same-site"已为 Chrome 51 和 Opera 39 实现了该属性...

I recently read "RFC 6265" on the attribute "Same Site", I looked at some articles that talked about that in April 2016, "same-site" attribute has been implemented for Chrome 51 and Opera 39 ...

不知道当前的 PHP 是否支持使用此属性创建 cookie?

I wonder if current PHP supports creating cookies with this attribute?

参考:

推荐答案

[重要更新: 正如@caw 在下面指出的,这个 hack 将在 PHP 7.3 中崩溃.立即停止使用它,以免您遇到令人不快的意外!或者至少将它包装在 PHP 版本检查中,例如 if (PHP_VERSION_ID < 70300) { ... } else { ... }.]

[Important update: As @caw pointed out below, this hack WILL BREAK in PHP 7.3. Stop using it now to save yourself from unpleasant surprises! Or at least wrap it in a PHP version check like if (PHP_VERSION_ID < 70300) { ... } else { ... }.]

似乎您可以滥用 PHP 的setcookie"函数的path"或domain"参数来潜入 SameSite 属性,因为 PHP 不会转义分号:

It seems like you can abuse the "path" or "domain" parameter of PHP's "setcookie" function to sneak in the SameSite attribute because PHP does not escape semicolons:

setcookie('samesite-test', '1', 0, '/; samesite=strict');

然后 PHP 发送以下 HTTP 标头:

Then PHP sends the following HTTP header:

设置-Cookie:samesite-test=1;路径=/;samesite=strict

Set-Cookie: samesite-test=1; path=/; samesite=strict

我几分钟前才发现这一点,所以请自行测试!我使用的是 PHP 7.1.11.

I've just discovered this a few minutes ago, so please do your own testing! I'm using PHP 7.1.11.

这篇关于PHP setcookie“SameSite=Strict"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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