1

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

lvil
  • 4,326
  • 9
  • 48
  • 76

3 Answers3

3

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

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

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

bumperbox
  • 10,166
  • 6
  • 43
  • 66
0
  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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • thank you for -1 and advices (though the function was not written by me, copypasted it from code written before me) – lvil Oct 11 '11 at 09:29
  • -1 is not for the function but for the way you posted: not a real code you run. So, there is no reason to answer at all, as there can be any number of the further corrections. – Your Common Sense Oct 11 '11 at 09:41