PHP

Is there a difference when deleting cookies using the PHP setcookie() Function by using "0" or "false" as Boolean values instead of using an empty string (like this " ")?

  • PHP
  • Backend
  • Cookie
  • Cookies
  • setcookie()
  • Deleting

1 comments

Hi Arun,


1. If you are looking to set your cooking to "0", it should be 0 without the double-quotes.
setcookie("isLoggedIn", 0, time() - 3600);

2. If you set the cookie as false or 0, it will also work, but instead of clearing the cookie, you are still setting a value to it, just that this time it's false.
If you are not using isset($_COOKIE["isLoggedIn"]), you can set the cookie to false or 0, but if you are, you will not be able to do that as the "isset" function detects whether or not the cookie exist, which in this case it still does just that it's false / 0.

I hope I answer your question.