Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

Happens in both Firefox and IE8

share|improve this question

2 Answers 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.

share|improve this answer

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

share|improve this answer
Grazie della risposta! The cookie exists alright; it is correctly read on the pages of mydomain.net. –  stevenvh Aug 22 '10 at 14:36
@stevenvh: Prego :) . Is there a cookies set for 'visitor' on subdomain.mydomain.net? This would overwrite the 'visitor' on .mydomain.net –  Luca Matteis Aug 22 '10 at 14:43
no (inglese: "no" ;-)), there are no cookies except the global one. –  stevenvh Aug 22 '10 at 15:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.