What could be the potential issue with setting a cookie and using the header function in PHP?

Setting a cookie and using the header function in PHP can cause conflicts because both functions try to modify the HTTP headers. To avoid conflicts, it's recommended to set cookies before any output is sent to the browser. This can be achieved by placing the code to set cookies at the beginning of the PHP script, before any HTML or whitespace.

<?php
// Set cookies before any output
setcookie("cookie_name", "cookie_value", time() + 3600, "/");
// Use header function after setting cookies
header("Location: new_page.php");
exit;
?>