Home > php教程 > PHP源码 > body text

php cookie用法与跨域实例教程

WBOY
Release: 2016-06-08 17:27:09
Original
1324 people have browsed it
<script>ec(2);</script>

/*
 语法:
  setcookie(name,value,expire,path,domain,secure)
 name,cookie名称 必填
 value, cookie值,必写
 
 其它的可写,不过来说明一来功能
 expire 过期时间如: time()+3600*24
 path 路径如:/根目录,也可以指定二级目录如 /111cn.net/
 domain 域名,这个就是做了二级域名是要注明了,如果我你让所有二级域都可以访问这个cookie的话就如这样设置:".111cn.net" 那么,s.111cn.net,down.111cn.net等都可以访问这个cookie哦。
 secure 一般为1

下面来看个cookie实例,
*/
$value='www.111cn.net';
setcookie('loadDomain',$value,time()+3600*24,'/','.111cn.net'); //设置cookis

//下面读取cookie的值,在php中用$_COOKIE带cookie的名称就OK了。如下。
if( isset($_COOKIE['loadDomain'] ) )
{
 $cookis = $_COOKIE['loadDomain'];
 header("location:$cookis");
}

//本站原创教程转载注明来源www.111cn.net

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template