Tools, FAQ, Tutorials:
Removing a Cookie in PHP
How To Remove a Cookie in PHP?
✍: FYIcenter.com
Once a cookie is sent from the server to the browser, there is no direct way for the server to ask the browser to remove the cookie. But you can use the setcookie() function to send the same cookie to browser with a negative expiration time, which will cause the browser to expire (remove) the cookie immediately. The next sample PHP page will let you remove "CouponNumber" and CouponValue" persisted by the previous tutorial exercise:
<?php
setcookie("CouponNumber","",time()-1);
setcookie("CouponValue","",time()-1);
print("<pre>\n");
print("2 cookies were delivered with past times.\n");
$count = count($_COOKIE);
print("$count cookies received.\n");
foreach ($_COOKIE as $name => $value) {
print " $name = $value\n";
}
print("</pre>\n");
?>
Open your browser to visit this page: http://localhost/removing_cookies.php. You will see:
2 cookies were delivered with past times. 2 cookies received. CouponNumber = 07470433 CouponValue = 100.00
Click the refresh button, you will see:
2 cookies were delivered with past times. 0 cookies received.
As you can see, both cookies are removed.
⇒ Domain and Path Attributes for Cookies in PHP
⇐ Testing Persistent Cookies in PHP
2016-11-03, ∼2149🔥, 0💬
Popular Posts:
How to add request URL Template Parameters to my Azure API operation to make it more user friendly? ...
How to read Atom validation errors at w3.org? If your Atom feed has errors, the Atom validator at w3...
How to use the JSON to XML Conversion Tool at utilities-online.info? If you want to try the JSON to ...
How To Pad an Array with the Same Value Multiple Times in PHP? If you want to add the same value mul...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...