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

2 Answers 2

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);

3
  • Grazie della risposta! The cookie exists alright; it is correctly read on the pages of mydomain.net.
    – stevenvh
    Aug 22, 2010 at 14:36
  • @stevenvh: Prego :) . Is there a cookies set for 'visitor' on subdomain.mydomain.net? This would overwrite the 'visitor' on .mydomain.net Aug 22, 2010 at 14:43
  • no (inglese: "no" ;-)), there are no cookies except the global one.
    – stevenvh
    Aug 22, 2010 at 15:50
-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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .