我希望有人能给我一些关于我的问题的想法。我正在尝试应用 SameSite cookie 来使 session 工作,但它似乎不起作用。访问的网站html:
<iframe src="https://www.example.com/test/iframe.php"></iframe>
iframe 源站点:
<?php
header('Set-Cookie: cross-site-cookie=PHPSESSID; SameSite=None; Secure');
session_start();
if(!isset($_SESSION['test'])){
echo 1;
$_SESSION['test'] = 'ee2';
}else{
echo $_SESSION['test'];
}
如果我访问该网站,我仍然收到
A cookie associated with a cross-site resource at https://www.example.com/ was set without the SameSite attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with SameSite=None and Secure.
浏览器控制台中的消息和 session 未保存。奇怪的是,cookie实际上已经设置好了:
我错过了什么吗?如果设置了跨站点 cookie,为什么我会在控制台中收到此消息, session 不工作的原因可能是什么?我正在使用 php 7.1.33。如果我直接打开 iframe,它可以正常工作,并且如果我使用浏览器打开站点,但在默认情况下没有启用 SameSite cookie 标志进行测试,它也可以正常工作。
最佳答案
我通过编辑 .htaccess 解决了它
<ifmodule mod_headers.c>
Header always edit Set-Cookie ^(.*)$ $1;SameSite=None;Secure
</ifmodule>
关于PHP SameSite session 问题, session 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60157086/