php中cookie实现二级域名可访问操作实例
Jun 02, 2016 am 09:14 AM有时候两个域名可能在不同的服务器上,但是我们依然希望二级域名能够顺利访问主域名的cookie,主域名可以顺利访问二级域名的cookie。比如bbs.www.phprm.com 希望能访问www.phprm.com和blog.www.phprm.com的cookie
下面介绍3种你可能常听到的全局cookie设置方式
代码如下 | 复制代码 |
setcookie("hzhuti",$s,time()+3600*12,'/','*.www.phprm.com'); |
*号无法成功设置一个cookie
代码如下 | 复制代码 |
setcookie("hzhuti",$s,time()+3600*12,'/','.www.phprm.com'); |
成功设置一个全局cookie ss.www.phprm.com下也能正确读取
代码如下 | 复制代码 |
setcookie("hzhuti",$s,time()+3600*12,'/','www.phprm.com'); |
成功设置一个全局cookie ss.www.phprm.com下也能正确读取
这种方式月小升的理解是仅仅www.phprm.com能够读取。月小升在FireFox下测试成功。IE下成功
代码如下 | 复制代码 |
setcookie("hzhuti",$s,time()+3600*12,'/','ss.www.phprm.com'); |
设置一个仅仅在ss.www.phprm.com域名下可以正确读取的cookie
网络上标准的说法为.www.phprm.com这样。
也有*的说法(该说法完全错误。。。)
下面推荐一个不错的php cookie操作的类,可以设置cookie、获取cookie、删除cookie。
代码如下 | 复制代码 |
/** function PHP_COOKIE($cname, $cexpires="", $cdir="/", $csite="") if($cexpires){ $this->_dir=$cdir; function extract($cname="") if(empty($cname) && isset($this)){ if(get_magic_quotes_gpc()){ if($arr!==false && is_array($arr)){ foreach($arr as $var => $val){ $_COOKIE[$var]=$val; if(isset($GLOBALS["PHP_SELF"])){ if(isset($this)) $this->_val=$arr; } function put($var, $value) if(isset($GLOBALS["PHP_SELF"])){ if(empty($value)){ } function clear() function set() |
教程地址:
欢迎转载!但请带上文章地址^^

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList?

How to determine the number of foreach loop in php

PHP returns an array with key values flipped

PHP returns the current element in an array

How to iterate through the properties of an object using the forEach function?

What is the difference between foreach and for loop

How to get the index value of the current element in php foreach loop
