What potential pitfalls should be considered when using the header() function in PHP for page redirection?
One potential pitfall when using the header() function for page redirection in PHP is that it must be called before any output is sent to the browser. Otherwise, you may encounter "headers already sent" errors. To avoid this issue, you can use output buffering to capture any output before sending headers.
<?php
ob_start(); // Start output buffering
// Your PHP code here
ob_end_clean(); // Clean the output buffer without sending it to the browser
header("Location: newpage.php");
exit;
?>