发布于 2015-02-19 13:52:45 | 433 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

微软IE浏览器

ie(微软公司出品的网页浏览器) 即 Internet Explorer 。 Internet Explorer,原称Microsoft Internet Explorer和Windows Internet Explorer,简称 IE,是微软公司推出的一款网页浏览器。


本文为大家讲解的是php中 cookie的作用域使用说明,感兴趣的同学参考下。


域名和cookie
偶然想到一个问题:www.g.cn能把cookie设置为.g.cn,那么www.com.cn能设置把cookie设置为.com.cn吗?

试验结果:不能。因为浏览器知道www.com.cn的后缀是.com.cn而不是.cn,所以禁止设置cookie。
因为浏览器内置了域名后缀列表。todo:如果以后出现新的后缀,而老浏览器没法更新列表,岂不是会允许设置cookie?
 

  extension后缀 一级域名 二级域名
www.g.cn .cn g.cn *.g.cn
www.com.cn .com.cn www.com.cn *.www.com.cn
www.google.com.cn .com.cn google.com.cn *.google.com.cn


www.example.com能读取到.example.com的cookie吗?
能。
www.example.com能读取到example.com的cookie吗?
不能。todo:把www.example.com和example.com做SSO,即可防止cookie带到static.example.com。
example.com能读取到www.example.com的cookie吗?
答:不能。
setcookie('a', 'aa', time() + 1234, '/', 'example.com'); 设置的cookie是 .example.com 还是 example.com的?
答:是.example.com的。
如果想设置example.com的cookie,需要使用setcookie('default', 'default', time() + 1234, '/');。
cookie的设置和读取范围:

 

 

HTTP请求域名 一级域名 cookie可设置(并可读取)的范围 cookie不可设置 cookie不可读取
example.com example.com example.com,.example.com www.example.com www.example.com
www.example.com example.com www.example.com,.www.example.com,.example.com example.com example.com
g.com.cn g.com.cn g.com.cn,.g.com.cn .com.cn  
www.com.cn www.com.cn www.com.cn,.www.com.cn .com.cn


设置cookie代码:

 

 

 


<?php
setcookie('default', 'default', time() + 1234, '/');
setcookie('a', 'aa', time() + 1234, '/', 'example.com');
setcookie('b', 'bb', time() + 1234, '/', '.example.com');
?>


读取cookie代码:

 

 


<?php
var_dump($_COOKIE);
?>


结果截图:

 

 

 



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务