Share on Google+Share on Google+

Delete Cookie

In this example you will learn how to delete cookie in PHP.

Delete Cookies

In the following program, you will learn how to delete the cookie through setting session. 

In the given example, we have set the value of cookie after one month of generating and before one hour of system date. 

For deleteing the cookies, you will have to set the cookie expire time ahead of the system time or before of the system time as we have set one month later time after generating it and one hour before the system time.

We have tried to get two output from this program, first we gave $_cookie () to view only one cookie value, while for viewing all cookie value, we have set r_cookie () function. 

setcookie("cookie", "Rose India", $expire);
echo $_COOKIE["cookie"]; # view one cookie value 
echo "<br/>";
print_r($_COOKIE); # view all cookie value
setcookie("cookie", "", time()-3600);
echo "Cookie deleted";

In the first results, the output will come with cookie value. while in second result, the print of cookie deleted exist.



Posted on: July 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.