当前位置:和仁网 >生活 > 正文

cookie跨域,二级域名之间如何共享

2021-06-25 2

TP5解决方案
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
cookie => [
// cookie 名称前缀
prefix => ,
// cookie 保存时间
expire => 0,
// cookie 保存路径
path => /,
// cookie 有效域名
domain => , // 这里是重点
// cookie 启用安全传输
secure => false,
// httponly设置
httponly => ,
// 是否使用 setcookie
setcookie => true,
],
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
其它
cookis 设置,读取方法,跨域[二级域名]
$time =30;
$domain =.111cn.net;
setcookie("abcde","aaaaaa");//最简单的cookie设置方法
setcookie(load,www.111cn.net,time()+3600*24,/,.111cn.net); //这里可以设置二级域名
$cookis = $_COOKIE[loadDomain];//读取域名
print_r( $cookis );
/*
来看几个例子:
简单的:
SetCookie("MyCookie", "Value of MyCookie");
带失效时间的:
SetCookie("WithExpire", "Expire in 1 hour", time()+3600);//3600秒=1小时
什么都有的:
SetCookie("FullCookie", "Full cookie value", time()+3600, "/forum", ".111cn.net", 1);
*/
?>
<script language="javascript教程">
function setcookie(name,days)
{
var url = document.domain;
var exp = new Date();
exp.setTime(exp.getTime() + days*24*60*60*1000);
document.cookie = name + "="+ escape(url) +";expires="+ exp.toGMTString();
}
function getcookie(name)
{
var arr = document.cookie.match(new RegExp("[sS]*"+ name +"=([^;]*)"));
alert(arr);
if(arr != null)
return unescape(arr[1]);
return null;
}
</script>
//php教程 cookies
//asp教程 cookies
Response.Cookies("Uto")("UtorName")=UtorName
Response.Cookies("Uto")("UtorPwd")=UtorPwd
Response.Cookies("Uto").Domain="utoper.com"
Response.Cookies("Uto").Secure =False
本周热门
本月热门