What are the consequences of sending headers after output in PHP?

Sending headers after output in PHP can result in the "headers already sent" error, which can prevent headers from being set properly and cause issues with redirects, cookies, and other HTTP-related functionality. To solve this issue, make sure to set headers before any output is sent to the browser.

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

// Set headers before any output
header('Content-Type: text/html');

// Output content
echo 'Hello, World!';

ob_end_flush(); // Flush output buffer
?>