What are some common mistakes to avoid when working with headers and data in PHP?

One common mistake to avoid when working with headers and data in PHP is sending headers after outputting data to the browser. This can lead to errors like "headers already sent" because headers must be sent before any output is sent to the browser. To avoid this, make sure to set headers before any output is generated in your PHP script.

<?php
// Correct way to set headers before outputting data
header('Content-Type: text/html');
echo "Hello, World!";
?>