Multiple cookie - array style of cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

Multiple cookie - array style of cookie

Post 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]
Last edited by fitchic77 on Sat Oct 16, 2010 11:42 am, edited 1 time in total.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

Hi fitchic77

you could probably do this:

Code: Select all

<?php
unset($_COOKIE);
?>
AngryPanda
Forum Newbie
Posts: 16
Joined: Wed Jul 19, 2006 12:18 am

Post 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...
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

THANKS!

Post by fitchic77 »

Ok. Great. I'll try some of these.

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


8O
Last edited by fitchic77 on Sat Oct 16, 2010 11:43 am, edited 1 time in total.
User avatar
kbrown3074
Forum Contributor
Posts: 119
Joined: Thu Jul 20, 2006 1:36 pm

Post by kbrown3074 »

Try setting the cookie to have an empty value. Manually set it once you are done using the specific cookie.
fitchic77
Forum Commoner
Posts: 51
Joined: Thu Jul 20, 2006 11:57 pm

Post 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";
}
Post Reply