What are the best practices for structuring PHP scripts to avoid header-related errors in Apache?

When working with PHP scripts in Apache, it is important to ensure that headers are sent before any content is output to the browser. To avoid header-related errors, it is recommended to structure your PHP scripts in a way that headers are sent at the beginning of the script, before any HTML or other output. This can be achieved by placing any header-related functions, such as `header()` or `session_start()`, at the very top of your PHP script.

<?php
// Send headers before any output
header('Content-Type: text/html');

// Start the session
session_start();

// Rest of your PHP code goes here
?>