What are common issues with including PHP scripts in a webpage and encountering "Header already sent" errors?

When including PHP scripts in a webpage, a common issue is encountering "Header already sent" errors. This error occurs when there is whitespace or output before the header() function is called in the PHP script. To solve this issue, make sure there is no whitespace or output (such as HTML tags or echo statements) before calling the header() function.

<?php
ob_start(); // Start output buffering
// Place all PHP code before any output or whitespace
header("Location: example.php");
ob_end_flush(); // Flush output buffer and send headers
?>