What potential issues can arise when using the header function for redirection in PHP?

One potential issue that can arise when using the header function for redirection in PHP is that headers must be sent before any output is displayed on the page. If there is any output, such as HTML content or whitespace, before the header function is called, it will result in a "headers already sent" error. To solve 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;
?>