I'm trying to set cookies on my project, but it is not working on Safari or Firefox.
I get results on Google Chrome though.
Here is my code:
setcookie('mycookiename', 'data', time()+60*60*24*365, '/', false);
print_r($_COOKIE['mycookiename']);
Thanks for help.
答案 0 :(得分:1)
This code work properly
setcookie("mycookiename", 'data', time()+60*60*24*365, "/", "", "", TRUE);
print_r($_COOKIE['mycookiename']);
答案 1 :(得分:0)
对我来说是因为ajax和fetch。
获取不会发送Cookie,除非您设置凭据初始化选项:
fetch(url, {
method: 'POST',
credentials: 'same-origin',
headers: {...},
...
});
如果您正在执行跨源请求,似乎也应该设置Access-Control-Allow-Credentials: true
标头。看到这个:
https://stackoverflow.com/a/40255834/4718434