What are potential pitfalls when using the header function in PHP to redirect to another page?

Potential pitfalls when using the header function in PHP to redirect to another page include headers already being sent, leading to errors or unexpected behavior. To avoid this, make sure to call the header function before any output is sent to the browser.

<?php
// Correct way to redirect using header function
header("Location: newpage.php");
exit();
?>