Home Tutorial Php Examples Delete Cookie

 
 

Delete Cookie
Posted on: July 31, 2009 at 12:00 AM
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. 

<?php
$expire=time()+60*60*24*30;
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.

Related Tags for Delete Cookie:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.