What are the potential pitfalls of using header() for automatic redirection in PHP?
Using header() for automatic redirection in PHP can lead to potential pitfalls such as headers already being sent to the browser, which can cause errors or unexpected behavior. To avoid this issue, it is recommended to use the ob_start() function to buffer the output before sending any headers.
<?php
ob_start();
// Your PHP code here
// Redirect to a new page
header("Location: newpage.php");
exit();
ob_end_flush();
?>