Hai friends

I need one clarification for cookies . How to distroy the cookies using php .
Please help me

Thanks
vssp

Hai friends

I need one clarification for cookies . How to distroy the cookies using php .
Please help me

Thanks
vssp

Setting a cookie with no value is the same as deleting it.

eg:

setcookie( 'cookie_name', 'cookie value');

setcookie( 'cookie_name'); // deletes the cookie named cookie_name

The problem with this method is that it doesn't destroy the cookie, it just erases the data contained within it. Sort of a bummer.

I looked on php.net to see if I could find a method made explicitly to destroy cookies, but had no luck. The one way that I have found is to set the cookie's expiration time to some time in the past. Then the browser, using some sort of voodoo, will destroy the cookie.

Comments
3 year bump? really?

The problem with this method is that it doesn't destroy the cookie, it just erases the data contained within it. Sort of a bummer.

I looked on php.net to see if I could find a method made explicitly to destroy cookies, but had no luck. The one way that I have found is to set the cookie's expiration time to some time in the past. Then the browser, using some sort of voodoo, will destroy the cookie.

Setting an expiration date in the past to delete a cookie is actually documented on the setcookie page on PHP.net

When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:

<?php
// set the expiration date to one hour ago
setcookie ("TestCookie", "", time() - 3600);
setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1);
?>

ugh, php can be so hacky sometimes. Though I guess you could just put that in a wrapper function or something.

Setting a cookie to the past has nothing to do with PHP being hacky, it forces the browser (which is what's being hacky) to delete the cookie which is a file on the client computer. There is no way PHP could touch a client filesystem (when used in a browser, obviously it could do it if used outside of a web environment)

This article has been dead for over six months. Start a new discussion instead.