By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

URGENT: cookies not working anymore!

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.