tags:

views:

195

answers:

1

i have created a cookie with:

$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()+60*60*24*365, '/', $domain, false);

but how do i delete it?

i tried with just switching the + to - but it didnt work.

$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('cookiename', 'data', time()-60*60*24*365, '/', $domain, false);
A: 
setcookie('fayer', FALSE, 1);

And make sure to use the same paramaters that you used while creating the cookie. If you had restricted the cookie to a domain, you must mention that while deleting the cookie too.

The browser deletes the cookie only when the parameters match.

For example, if you created the cookie like this:

setcookie('fayer', "some value", time()+24600, "/", "www.fayer.com", 0);

you must delete the cookie this way:

setcookie('fayer', FALSE, 1, "/", "www.fayer.com", 0);
Nirmal
nope..doesnt work!:( what is the problem??
never_had_a_name
Please see my updated answer.
Nirmal
please see my updated answer=)
never_had_a_name
what if im working local. should i have the 5th argument as "localhost"?
never_had_a_name
No. 'localhost' is not a valid value. You should use false instead.
Nirmal