setcookie使用localhost不能成功的问题

本文探讨了在 localhost 下设置 cookie 的常见问题及其解决方案。详细解释了为什么 'localhost' 作为域名无效,并提供了如何正确设置 cookie 以便在 localhost 和实际域名下都能正常工作的示例代码。

问题:

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:

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值