URGENT: cookies not working anymore!

  • Follow


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!!



0
Reply craig1972 (2) 8/2/2003 3:32:48 AM

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

0
Reply liquidlaughter2000 (59) 8/2/2003 8:46:31 AM


1 Replies
26 Views

(page loaded in 0.046 seconds)

Similiar Articles:










7/15/2012 1:53:30 PM


Reply: