What are common causes of the "Cannot modify header information" error in PHP scripts?

The "Cannot modify header information" error in PHP scripts commonly occurs when there is output being sent to the browser before the header() function is called to modify HTTP headers. To solve this issue, make sure that there is no whitespace or any other output before the header() function is called.

<?php
ob_start(); // Start output buffering

// Your PHP code here

ob_end_flush(); // Flush output buffer