问题:
setcookie("severss", "ss",$num, '/','localhost');
SetCookie("sever","dd",$num,"/","127.0.0.1")
两个setcookie都成功!
但是用localhost的那个在localhost域名下就不可以访问
而127.0.0.1在127.0.0.1下能访问
这是为什么阿?
要怎么写才能在localhost下设置cookie成功呢?
怎样在http://localhost/kongjian/admin.php/account/login下设置cookie然后在http://localhost/kongjian/下边也可以访问到?
手册上这么说:
something that wasn't made clear to me here and totally confused me for a while was that domain
names must contain at least two dots (.),
hence 'localhost' is invalid and the browser will refuse to set the cookie!
instead for localhost you should use false.
to make your code work on both localhost and a proper domain, you can do this:
本文探讨了在 localhost 下设置 cookie 的常见问题及其解决方案。详细解释了为什么 'localhost' 作为域名无效,并提供了如何正确设置 cookie 以便在 localhost 和实际域名下都能正常工作的示例代码。
1131

被折叠的 条评论
为什么被折叠?



