如何修复 SameSite 属性警告?

How to fix the SameSite attribute warning?

A cookie associated with a cross-site resource at https://cloudflare.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

我解决这个问题重要吗?我该如何解决这个问题?我在网站顶部添加了它,但没有解决任何问题。

<?php
    header('Set-Cookie: cross-site-cookie=name; SameSite=None; Secure');
?>

一般来说,这些警告目前仅供参考,不会影响您的网站行为。不过,由于在 2020 年 2 月左右达到稳定,这些将成为 Chrome 80 的默认值。

在这种情况下,cookie 来自 https://cloudflare.com。由于那不是您的域,因此您在网站代码中放置的任何内容都不会影响该 cookie。这里要检查两件事:

  1. 如果 CloudFlare cookie 是您在您的帐户中明确设置的,例如也许通过工作人员设置 cookie,然后您需要在那里更新 SameSite 属性。
  2. 如果此 cookie 来自您不负责的 CloudFlare 功能,则您无需采取任何措施。 CloudFlare 负责管理这些 cookie 并更新属性。

所以,你的 PHP code looks fine but it will not be affecting cookies outside of your site. You can check https://web.dev/samesite-cookies-explained 了解更多背景信息。