how to delete all the values 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
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

how to delete all the values of cookie

Post 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?
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post 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
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post 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
wh33t
Forum Newbie
Posts: 12
Joined: Wed Nov 30, 2005 2:09 am

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

You can also set all values to ""
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
Post Reply