Home Tutorial Php Examples Delete Cookie

 
 

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

Advertisement

Related Tags for Delete Cookie:


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.

Posted on: July 31, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com