lvil
lvil

Reputation: 4326

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 the cookie on www.mysite.com and sub1.mysite.com.
The directories are:

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

Upvotes: 1

Views: 650

Answers (3)

Your Common Sense
Your Common Sense

Reputation: 157839

  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.

Upvotes: 0

xdazz
xdazz

Reputation: 160833

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

Upvotes: 3

bumperbox
bumperbox

Reputation: 10214

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

Upvotes: 1

Related Questions