What role does whitespace and HTML code play in causing errors when setting cookies in PHP?

Whitespace and HTML code can cause errors when setting cookies in PHP because any output sent to the browser before setting a cookie will result in an error. To prevent this, make sure there is no whitespace or HTML code before the `setcookie()` function is called.

<?php
ob_start(); // Start output buffering
// Your PHP code here
ob_end_clean(); // Clean the output buffer
setcookie("cookie_name", "cookie_value", time() + 3600, "/"); // Set the cookie
?>