What are the potential issues with outputting HTML before using header() in PHP?

Outputting HTML before using header() in PHP can cause issues because headers must be sent before any output is sent to the browser. This can result in a "headers already sent" error message. To solve this issue, make sure to call header() before any HTML output, or use output buffering to store the output before sending it to the browser.

<?php
ob_start(); // Start output buffering

// Any HTML output or code here

header("Location: https://www.example.com"); // Redirect header

ob_end_flush(); // Flush the output buffer
?>