How to destroy or remove a cookie in PHP

October 26, 2018

To remove a cookie, you should set its expiry to a date in the past.

<?php
setcookie("the_cookie_name", "", time()-(60*60*24*7));
// or also set the path, if it was set with a path:
setcookie("the_cookie_name", "", time()-(60*60*24*7),"/");

And then the next time the user loads a page (or makes a request), their browser will remove the cookie.

You should also clear PHP's 'copy' of the cookie:

<?php
unset($_COOKIE["the_cookie_name"]);