What is the common error message when using setcookie in PHP?
When using setcookie in PHP, a common error message is "Cannot modify header information - headers already sent". This error occurs when there is any output (such as HTML, whitespace, or error messages) sent to the browser before calling setcookie. To solve this issue, make sure to call setcookie before any output is sent to the browser, including any whitespace.
<?php
// Correct way to set a cookie in PHP
ob_start(); // Start output buffering
setcookie("cookie_name", "cookie_value", time() + 3600, "/");
ob_end_flush(); // Flush the output buffer
?>