Page 1 of 1

Multiple cookie - array style of cookie

Posted: Fri Jul 21, 2006 12:03 am
by fitchic77
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here I'm setting "myCookie" in .php.

Code: Select all

setcookie("myCookie[fname]",  "Paula", time() +3600); 
setcookie("myCookie[lname]",  "Smith", time() +3600);
I can't figure out how to clear out the "myCookie" without individually doing:

Code: Select all

setcookie("myCookie[fname]",  "", time() -1); 
setcookie("myCookie[lname]",  "", time() -1);
Is there a way I could just clear out all the elements in a multiple cookie.

This doesn't work:

Code: Select all

setcookie("myCookie[]",  "", time() -1);
NOR

Code: Select all

setcookie("myCookie",  "", time() -1);


Thanks,

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.2"][b]12.b.[/b] You may not advertise in your signature.[/quote]

Posted: Fri Jul 21, 2006 5:35 am
by thomas777neo
Hi fitchic77

you could probably do this:

Code: Select all

<?php
unset($_COOKIE);
?>

Posted: Fri Jul 21, 2006 5:59 am
by AngryPanda
I don't think that will work. That will just unset the superglobal array, not the cookie itself (could be wrong). Perhaps something like this..

Code: Select all

foreach($_COOKIE as $k => $v)
{
setcookie($k, "", time() - 3600);
}
Because each key in the _COOKIE array is the name of the cookie, right ? Might need tweaking but it seems like that would work...

THANKS!

Posted: Fri Jul 21, 2006 1:24 pm
by fitchic77
Ok. Great. I'll try some of these.

How would I check to see if the cookie is cleared or not?


8O

Posted: Fri Jul 21, 2006 1:30 pm
by kbrown3074
Try setting the cookie to have an empty value. Manually set it once you are done using the specific cookie.

Posted: Fri Jul 21, 2006 1:33 pm
by fitchic77
What I'm asking is?

Is this a valid check...cause it doesn't seem to be working since it is an array style of cookie....

if ($isset($_COOKIE['nameCookie'] )) {
echo "here";
}else{
echo "there";
}