0

I've written a cookie for my domain + subdomain:

setcookie("visitor", $visitor, time()+60*60*24*365, "/", ".mydomain.net");

but when I try to read it from within subdomain.mydomain.net, it's empty. Could it be that $_COOKIE[] tries to read the cookie for the subdomain instead of reading the global one? How do I fix this?
TIA
Steven

Edit
Happens in both Firefox and IE8

stevenvh
  • 103
  • 2
  • 4
  • 8

2 Answers2

1

You should check in your browser if the cookie actually exists for .mydomain.net (be sure the www part is excluded).

If that's the case then you should be able to read it from any .mydomain.net sub-domain using $_COOKIE['visitor'] in PHP.

Just in case try dumping the $_COOKIE data by doing print_r($_COOKIE);

Luca Matteis
  • 548
  • 4
  • 11
  • 21
-2

I had the same problem when I was trying to set the cookie while in the subdomain. After I set the cookie from the top domain, everything worked great. Something about setting the cookie from the subdomain will not set the cookie.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
Randy
  • 1
  • 1