How can including files in PHP affect the session_start() function and cause header-related errors?

When including files in PHP before calling the session_start() function, any whitespace, HTML output, or characters outside of the PHP tags can cause header-related errors. To solve this issue, make sure to include files that only contain PHP code and do not output any content before the session_start() function is called.

<?php
// Correct way to include files before session_start()
require_once 'file1.php';
require_once 'file2.php';

session_start();

// Rest of the PHP code
?>