Hi Everyone,

I created a script in my computer and the cookies worked just fine, but now after I've uploaded it to a server for some reason php cannot read the cookies.

For Example, when I've uploaded this code:

<?
setcookie("super_password", "hello", time()+3600, "/");
echo "the cookie is ".$_COOKIE["super_password"];
?>

It's returns nothing (not returning "hello". even after I've clicked "Refresh").

I tried the following things:
- I divided the script into 2 pages - one sets the cookie and reads it
- I checked the cookies in my browser and it's ok
- I used print_r($COOKIE["super_admin]); instead of echo $COOKIE["super_admin"];
- I removed the "/" domain section in the setcookie function

This Problem Happens only in IE - no matter what the privacy level is (even if it's accepts all cookies!)

Does anyone knows how can I solve this problem?

Thanks! That's really important...

Eyal

    Works fine for me in both IE7 and FF2 on my Windows Vista PC (after I changed the opening tag to "<?php" since I don't run PHP with short tags enabled).

    And just to clarify, it will only ever print the "hello" on a refresh or other re-access of the page once the cookie has been set, as on the initial page access there is no cookie to be retrieved from the client.

      Your code looks right and NogDog says it tests OK. So you may have problems only with your IE cookie cache, which can cause odd failures like the one you describe. Believe me, I've seen this behavior.

      Cllear your cookie cache (from the IE explorer menu;
      Tools>Internet Options
      General Tab>Browsing History
      Delete... button
      Delete cookies...

        You might also want to check your IE7 privacy settings (Tools -> Internet Options -> Privacy). If the privacy setting is "High", then it will only accept cookies from sites that have a "compact privacy policy".

          I found out something weird: IE accepts my cookie only if it's time being set to 0 like that:

          setcookie("name", "value", 0, "/");

          I cannot put something like "time()+3600" - it's don't accepts it.
          Does somebody know how can I solve that problem?

            What happens if you add a much larger value, (i.e.: time() + 60000)? I'm just wondering if there's some mismatch between the server clock and PC clock (though I have no idea why that would only effect IE).

              Write a Reply...