What are some common pitfalls when using header('Location:..') in PHP for redirecting to another page?

One common pitfall when using header('Location:..') in PHP for redirecting to another page is that there should be no output before the header function is called. This includes any HTML, whitespace, or even a BOM (Byte Order Mark) at the beginning of the file. To solve this issue, make sure to call the header function before any output is sent to the browser.

<?php
ob_start(); // Start output buffering
header('Location: new_page.php'); // Redirect to new_page.php
ob_end_flush(); // Flush the output buffer
exit; // Make sure to exit after the redirect
?>