...

View Full Version : Problem Viewing Cookies



eyalros
05-30-2007, 08:17 AM
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

printf
05-30-2007, 12:22 PM
a setcookie(), is never available on the same page it has been set on. The page must be redirected or refreshed to see the cookie that was just set!

CFMaBiSmAd
05-30-2007, 02:03 PM
Is your echo statement outputting anything, even just this part - "the cookie is "? If so, then stop using the short open PHP tag - <? and use the proper full PHP tag - <?php

Edit: After re-reading your original post, that this only occurs in IE, dis-regard what I wrote above.

However, you might have a cookie domain problem. Are you doing any url re-writing using a .htaccess file?

aedrin
05-30-2007, 03:28 PM
setcookie("super_password", "hello", time()+3600, "/");

Have you tried it without the last parameter?


a setcookie(), is never available on the same page it has been set on. The page must be redirected or refreshed to see the cookie that was just set!

The user already indicated two actions they took to make sure this was not the problem.

eyalros
05-31-2007, 02:29 PM
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?

CFMaBiSmAd
05-31-2007, 04:28 PM
Any chance that the server's time setting or the time on the computer you are trying this on could be set incorrectly?

The setcookie(...) is using the server's time, but once the cookie reaches the browser, the computer's time is being used to determine if the cookie has already expired. Try to set the expire time farther into the future and see if it starts working.

This note is from the setcookie() description in the manual -

expire is compared to the client's time which can differ from server's time.

By using 0 for the expire time, all the comparisons between the server and computer time are eliminated, which is why I suspect time difference between the two is what is causing this.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum