What is the correct syntax for deleting a cookie in PHP and what potential pitfalls should be considered?
To delete a cookie in PHP, you need to set the cookie with an expiration date in the past. This will prompt the browser to remove the cookie. It's important to note that the cookie must be unset before any output is sent to the browser to avoid any headers already being sent errors.
// Unset the cookie by setting its expiration date to the past
setcookie("cookie_name", "", time() - 3600, "/");
Keywords
Related Questions
- What are the potential security risks associated with not properly handling SQL injections in PHP?
- How can \n and \r be automatically removed from text stored in a database in PHP?
- Is it recommended to include PHP code directly in HTML files for generating dynamic content, or should a separate PHP file be used?