Cookie和子域 [英] Cookies And Subdomain

查看:68
本文介绍了Cookie和子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个包含多个子域的网站。

在主子域上设置了cookie:

  @setcookie($ name,$ value,$ expires,'/','.www.mysite.com'); 

我可以在www.mysite.com和sub1.mysite.com上看到Cookie。

目录是:




  • www.mysite.com:public / index.php

  • sub1.mysite.com:public / sub1 / index.php



我怎么可能看不到它?在新的子域sub2.mysite.com中?



sub2.mysite.com public / sub2 / index.php

解决方案

< blockquote>

将域设置为 www.example.com或 .www.example.com将使
使该Cookie仅在www子域中可用。


如果要使cookie在example.com的所有子域(包括example.com本身)上都可用,则将其设置为 .example.com'


There is a website with several subdomains.
On the main subdomain cookies are set:

 @setcookie( $name, $value, $expires, '/', '.www.mysite.com');  

I can see the cookie on www.mysite.com and sub1.mysite.com.
The directories are:

  • www.mysite.com: public/index.php
  • sub1.mysite.com: public/sub1/index.php

How can that be possible that I can't see it in the new subdomain sub2.mysite.com?

sub2.mysite.com public/sub2/index.php

解决方案

Setting the domain to 'www.example.com' or '.www.example.com' will make the cookie only available in the www subdomain.

If you want to make the cookie available on all subdomains of example.com (including example.com itself) then you'd set it to '.example.com'.

这篇关于Cookie和子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆