470,848 Members | 1,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

URGENT: cookies not working anymore!

hello, any idea why the following code does not work?!!

<?

$cookieExpire = 864000000;

setcookie("a", "love", $cookieExpire);
header("Set-Cookie: lc=50; expires=$cookieExpire");
header("Set-Cookie: id=test; expires=$cookieExpire");

while (list ($key, $val) = each ($_COOKIE)) {
echo "$key => $val<br />\n";
}

?>

Only the last cookie, "id=test" is set. Why?

Also, how should I delete all cookies set from my website in one command?

Thanks!!

Jul 16 '05 #1
1 5434
Why are you setting one cookie with setcookie() but setting the others
with header()? For testing reasons I presume. Get rid of the other
header() lines and just use setcookie().

Try setting $cookieExpire to time() + number of seconds (or decrease
$cookieExpire a bit - 86400 is 1 day so 864000000 is about 27 years...)

To delete a cookie, set it again (use setcookie()) with the value
parameter set to "" and everything else the same.

Use a browser such as Mozilla and set it to ask permission before a
cookie is set - you can see all the details of the cookie there, such as
the date it is due to expire. This makes it much easier to debug cookie
problems.

Hope this helps.

MK.

Craig Matthews wrote:
hello, any idea why the following code does not work?!!

<?

$cookieExpire = 864000000;

setcookie("a", "love", $cookieExpire);
header("Set-Cookie: lc=50; expires=$cookieExpire");
header("Set-Cookie: id=test; expires=$cookieExpire");

while (list ($key, $val) = each ($_COOKIE)) {
echo "$key => $val<br />\n";
}

?>

Only the last cookie, "id=test" is set. Why?

Also, how should I delete all cookies set from my website in one command?

Thanks!!


--
MeerKat

Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Spidah | last post: by
6 posts views Thread by Mark | last post: by
5 posts views Thread by Martin Heuckeroth | last post: by
6 posts views Thread by André | last post: by
1 post views Thread by maheshv | last post: by
7 posts views Thread by cmrchs | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.