How to remove a cookie with PHP?

Spread the love

Sometimes, we want to remove a cookie with PHP.

In this article, we’ll look at how to remove a cookie with PHP.

How to remove a cookie with PHP?

To remove a cookie with PHP, we call setcookie with a timestamp in the past and its value to an empty string.

For instance, we write

setcookie("hello", "", time() - 3600);

to call setcookie with the key of the cookie, empty string, and a timestamp in the past to remove the cookie with key 'hello'.

Conclusion

To remove a cookie with PHP, we call setcookie with a timestamp in the past and its value to an empty string.

Leave a Reply

Your email address will not be published.