PHP: How to destroy or remove a cookie in PHP
To remove a cookie, you should set its expiry to a date in the past.
- 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:
- unset($_COOKIE["the_cookie_name"]);
More...
Comments and discussion about How to destroy or remove a cookie in PHP
Found this interesting? Maybe you want to read some more in this series?
Or see other topics in the PHP language
Arrays
General
PHP Basics
Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScriptOr see random questions
Point all requests to one PHP file
How to set the timezone to UTC in .htaccess
What is snake case?
How to check if a object has a static variable defined?
Is multiple inheritance supported in PHP?
How to select all rows for a certain month (or day, year or time), using Eloquent
How to set the Expires header in .htaccess
What are Apache MPMs?
How to make Apache force download of files (in .htaccess)
How to fix the MySQL related "Specified key was too long error" error in Laravel