What are some best practices to avoid header-related errors in PHP scripts?

Header-related errors in PHP scripts often occur when headers are sent before any content, resulting in errors like "Cannot modify header information". To avoid this, make sure to call the `header()` function before any output is sent to the browser. Additionally, you can use the `headers_sent()` function to check if headers have already been sent before sending new headers. Example PHP code snippet:

<?php
if (!headers_sent()) {
    header('Content-Type: text/html');
}