What potential pitfalls should be avoided when using the header() function in PHP for redirecting users, and why is it important to include an exit statement after the header function?

When using the header() function in PHP for redirecting users, it is important to avoid sending any output before calling the function, as it will result in a "headers already sent" error. Additionally, it is crucial to include an exit statement after the header function to prevent any further code execution that may interfere with the redirection process.

<?php
// Ensure no output is sent before calling header function
ob_start();

// Redirect users to a new page
header("Location: new_page.php");

// Terminate script execution after redirection
exit;
?>