Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

but when I try to read it from within, 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

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

If that's the case then you should be able to read it from any 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 – stevenvh Aug 22 '10 at 14:36
@stevenvh: Prego :) . Is there a cookies set for 'visitor' on This would overwrite the 'visitor' on – 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

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

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.