In PHP, when does a header get sent to the browser? Is it only when there are outputs to the browser?

Headers in PHP are typically sent before any output is sent to the browser. If headers are sent after output, it can result in errors like "headers already sent". To ensure headers are sent before any output, you can use the `header()` function at the beginning of your PHP script before any other output is generated.

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

// Output content
echo "Hello, World!";
?>