How do I destroy cookies?

5,323 views
Skip to first unread message

Damelinks

unread,
Sep 30, 2008, 8:45:01 AM9/30/08
to PHP Programming
Goodday Everybody, I set cookie by using the codes below

<?php
$cookie_expire = time()+3600;
$cookie_name = "users";
$cookie_value = "$_POST[f_name] $_POST[s_name]";
$ret = setcookie('users', $cookie_value, $cookie_expire, "/");if (!
$ret)
{
echo "Unable ot set cookie";


}


?>

and the cookie was actually set and are working as espected but I am
trying to destroy the cookie using the codes below.


<?php
setcookie('users', 'NULL', mktime()-10000, '/');
?>


but it is not destroying the cookies. Please I need your help
because
I am using the cookies for users authentation.

Actually, i designed the website with my laptop and the cookie is
working very well there. But when I took the website to a desktop,
the cookies will set but refuse to destroy and I am using the cookie
for users authentation.

Thanks


Damelinks

Ricardo Matos

unread,
Sep 30, 2008, 1:42:38 PM9/30/08
to php_pro...@googlegroups.com
To destroy cookies:
setcookie("mycookie","",time()-3600);

where "mycookie" is the name your cookie

Hope it helps


-----Mensagem original-----
De: php_pro...@googlegroups.com
[mailto:php_pro...@googlegroups.com] Em nome de Damelinks
Enviada: terça-feira, 30 de Setembro de 2008 13:45
Para: PHP Programming
Assunto: How do I destroy cookies?

Beshoo

unread,
Oct 18, 2008, 9:17:24 AM10/18/08
to PHP Programming
Hi !
There is another way to deal with that,to delete it completely you
should unset it like :

unset($_COOKIE["mycookie"]);

However; the setcookie("mycookie","",time()-3600); of Mr.Ricardo
Matos, will leave it empty !

Basheer AL-Mansour
thanks.

Mustafa Atik

unread,
Oct 19, 2008, 5:20:19 AM10/19/08
to PHP Programming
<?php
setcookie('user','',time()-3600);
unset($_COOKIE['user']);
?>

parvez alam

unread,
May 18, 2012, 9:36:50 AM5/18/12
to php_pro...@googlegroups.com
Hi you cant set cookie time past for destroy cookie.

Reply all
Reply to author
Forward
0 new messages