Page 1 of 1

how to delete all the values of cookie

Posted: Wed Nov 30, 2005 3:15 am
by jaylin
now i store many values (like an array) in the cookie. although i use

Code: Select all

setcookie("mycookie","",time()-3600)
but, the values are still reamin. how can i clear them?

Posted: Wed Nov 30, 2005 3:27 am
by wh33t
You could clear them at the client level. Ie. Delete cookies from the Tools menu or whatever.

If you want to do it on the server level you could use unset() perhaps.

like

Code: Select all

unset($_COOKIE['arrayname']);
I think thats how unset works...

Check it out here

http://ca.php.net/manual/en/function.setcookie.php

Posted: Wed Nov 30, 2005 3:31 am
by jaylin
it doesn't work !!!
wh33t wrote:You could clear them at the client level. Ie. Delete cookies from the Tools menu or whatever.

If you want to do it on the server level you could use unset() perhaps.

like

Code: Select all

unset($_COOKIE['arrayname']);
I think thats how unset works...

Check it out here

http://ca.php.net/manual/en/function.setcookie.php

Posted: Wed Nov 30, 2005 3:32 am
by wh33t
Did you get an error message of some sort? Should probably post it if you did.

Also read up on that link I sent you. It will say how to delete and clear cookies.

Posted: Wed Nov 30, 2005 5:26 am
by Jenk
The only way to delete a users cookie from the server is to force it to expire, like you have done.

Try including your domain and cookie path, like is found on the manual page for setcookie(), that should solve it I reckon.

Posted: Wed Nov 30, 2005 5:59 am
by AGISB
You can also set all values to ""

Posted: Wed Nov 30, 2005 8:23 am
by shiznatix
AGISB wrote:You can also set all values to ""
if you do that then a isset check will still return TRUE. you could set all the values to NULL but why not just delete the cookies by giving them a negative time (a time in the past) as he was originally doing.