当从 example1.com 到 example2.com 进行 API 调用时,服务器是否可以将 cookie 设置为域为"example1.com"的客户端(example2.com example1.com
(我认为不可能将cookie从一个域设置为另一个域,因为如果发生这种情况,安全性将存在很多缺陷。
您需要 example2.com 来设置 cookie。如果 example1.com 将用户重定向到 example2.com/setcookie.php?example3=value
setcookie 脚本可以包含以下内容来设置 cookie 并重定向到正确的页面 example2.com
<?php
setcookie('example1', $_GET['example3']);
header("Location: example2.com/landingpage.php");
?>
欲了解更多信息,请访问:
https://stackoverflow.com/questions/6761415/how-to-set-a-cookie-for-other-domain#:~:text=Setting%20cookies%20for%20other%20domain,encode%20this%20into%20the%20url.&text=You%20can't%2C%20at%20minimum,be%20a%20nasty%20security%20risk.
关于类似的话题有很好的讨论。