setcookie使用localhost不能成功的问题
2010-08-22 12:45
477 查看
问题:
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:
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:
<?php $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false); ?>
相关文章推荐
- wampserver memcached安装成功不能使用的问题
- 关于使用API创建Rebar不能成功的问题
- mac os lion 上php连接mysql数据库不能使用使用localhost问题
- 使用Apache通过JK实现多Tomcat负载均衡集群时,Apache不能将请求分发给Tomcat处理(即Apache反向代理不成功)的问题
- mysql能用localhost连接不能使用127.0.0.1连接的问题之一
- wampserver memcached安装成功不能使用的问题
- SQL Server 2005数据库使用机器名称和localhost都能连接,但是使用IP地址却不能连接的问题
- 处理SDK编译成功后客户端不能使用的问题
- 关于Three20框架下的本地化不能使用的问题
- DotNetNuke3.0.8中不能使用中文页面名的问题
- emacs中不能使用fctix的问题解决
- 使用jspsmartupload解决表单属性为multipart/form-data不能传其他参数的问题
- Arcgis 图层编辑器“粘贴”功能菜单灰色不能使用的问题与解决办法
- Java基础问题:static方法中为什么不能使用非static的方法或变量
- SQL Server只能使用Windows身份登录,不能使用sa等Sql server身份进行登录”的问题
- 解决java使用Runtime.exec执行linux复杂命令不成功问题
- 关于登录弹层不能成功输入用户名密码的问题
- 微软Windows卸载工具--可解决更新Silverlight不能成功安装问题
- 在使用FileReader.readAsDataURL()时,处理不能不能连续选择同一个文件的问题
- IP地址修改后ORACLE不能使用问题