Apache 跨站点 cookie 共享问题

Apache cross site cookie sharing issue

我正在尝试做一些不寻常的事情。我有一个要从文件系统打开的 html 文档 (file:///usr/local/var/www/myFile.html)

在这个文件中,我通过 php:

从我的本地服务器加载脚本库
<script src="http://localhost/myscript.php" type="text/javascript">

这确实有效 - 这不是我的问题。我的问题是 session/cookies

首先,我使用 localhost/login.php

登录

当我通过 http://myFile.html 打开 myFile 时,myscript.php 有我在 login.php 中设置的会话和 cookie 变量。当我从文件系统打开 html 文件,然后通过 php 从服务器获取我的脚本时,它没有我的会话或 cookie 变量。 Chrome(客户端)标记会话和问题下的 cookie:

Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute Because a cookie’s SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being sent in a cross-site request. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery. Resolve this issue by updating the attributes of the cookie: Specify SameSite=None and Secure if the cookie should be sent in cross-site requests. This enables third-party use. Specify SameSite=Strict or SameSite=Lax if the cookie should not be sent in cross-site requests. 3 cookies

列出的其中一个 cookie 实际上是 PHP 会话 ID。另外两个是我在登录时设置的 cookie,作为没有我的会话变量的解决方法。

所以我去编辑了我的 php.ini 文件(我在另一个 php 页面上使用了 phpinfo() 以确保它是正确的 php.ini)

我做了这些改变

session.cookie_secure = 1
session.cookie_samesite = "None"

我重新启动了 httpd,但我仍然在 Chrome 中收到错误消息,并且会话和 cookie 未设置在我的 .php 文件中寻找它们的位置

我做错了什么/我在 php.ini 中遗漏了什么?

--- 编辑 ---

我在 Safari 中尝试了上面的方法并且成功了。看来问题出在 Chrome only

我认为回答的人没有理解我的问题,我可能对他们的误解有过错。

无论如何,我再次阅读来自 Chrome 的消息时发现,我还必须在我的 cookie 上设置 samesite 值。这是我在 login.php:

中的做法
    $res = $stmt->fetch(PDO::FETCH_ASSOC);
    $success = true;
    $_SESSION["editor"] = $_REQUEST["userID"];
    $_SESSION["agency"] = $res["id"];
//    setcookie("editor", $_POST["userID"], time() + 60 * 60 * 24, "/"); // 86400 = 1 day
//    setcookie("agency", $res["id"], time() + 60 * 60 * 24, "/"); // 86400 = 1 day
    setcookie("editor", $_POST["userID"], [
       "expires" => time() + 60 * 60 * 24,
       "path" => "/",
       "domain" => "", 
       "secure" => true,
       "httponly" => false,
       "samesite" => 'None'
      ]);

    setcookie("agency", $res["id"], [
       "expires" => time() + 60 * 60 * 24,
       "path" => "/",
       "domain" => "", 
       "secure" => true,
       "httponly" => false,
       "samesite" => 'None'
      ]);

这里我直接在我创建的 cookie 上设置“samesite”属性。现在cookie信息可以在http:///localhost/myscript.php in chrome