Removing a Cookie
suggest changeTo remove a cookie, set the expiry timestamp to a time in the past. This triggers the browser’s removal mechanism:
setcookie('user', '', time() - 3600, '/');
When deleting a cookie, the path and domain passed to
setcookie()must match the cookie you are deleting. Thesecure,httponly, andsamesiteattributes also identify the cookie. Otherwise a new cookie that expires immediately is created.
It is also a good idea to unset the $_COOKIE value in case the current page uses it:
unset($_COOKIE['user']);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents