What are common causes of "Cannot modify header information - headers already sent" errors in PHP?

The "Cannot modify header information - headers already sent" error in PHP occurs when there is output (such as echo, print, or whitespace) sent to the browser before the header() function is called to set HTTP headers. To solve this issue, make sure that there is no output sent to the browser before calling header() functions.

<?php
ob_start();
// Place this at the very beginning of the PHP script to buffer output

// Your PHP code here

ob_end_flush();
// Place this at the very end of the PHP script to send the buffered output