Cookies And Subdomain

前提是你 提交于 2019-12-24 11:08:56

问题


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


回答1:


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'.




回答2:


make sure the path is set to / so it works for the whole site, otherwise it might not work for sub directories on your site




回答3:


  1. Using @ is not a wise act in general but using it in front of setcookie() is exceptionally unwise, if not to say a stronger word.

  2. Subdomain should be set to .mysite.com'

  3. path should be set, not omitted. If you want to have access to the cookie in any directory, set path to /.

  4. Nevertheless, the reason can be any. One have to debug their code, not asking for the possible reasons.



来源:https://stackoverflow.com/questions/7723788/cookies-and-subdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!