How can output from include files affect the execution of header functions in PHP?

When including files in PHP, any output generated by the included file can affect the execution of header functions. This is because header functions must be called before any output is sent to the browser. To solve this issue, ensure that the included files do not generate any output before calling header functions.

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

include 'included_file.php';

ob_end_clean(); // Clean the output buffer without sending it to the browser

// Now it's safe to call header functions
header('Location: new_page.php');
exit;
?>