Cookies And Subdomain
There is a website with several subdomains.
On the main subdomain cookies are set: @setcookie( $name, $value, $expires, '/', '.www.mysite.com');
I can see 开发者_如何学Pythonthe 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'.
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
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.
Subdomain should be set to .mysite.com'
path should be set, not omitted. If you want to have access to the cookie in any directory, set path to
/
.Nevertheless, the reason can be any. One have to debug their code, not asking for the possible reasons.
精彩评论