What are the potential issues with using the header function after output has already been sent?
When output has already been sent to the browser, using the header function to set HTTP headers will result in an error. To solve this issue, you can check if any output has been sent using the headers_sent function before calling the header function.
if (!headers_sent()) {
header('Location: https://www.example.com');
exit;
} else {
// Handle error or redirect using JavaScript
echo '<script>window.location.href = "https://www.example.com";</script>';
}