How can one avoid the "Cannot modify header information" warning in PHP?

The "Cannot modify header information" warning in PHP occurs when there is an attempt to modify HTTP headers after data has already been sent to the browser. To avoid this warning, ensure that no output is sent to the browser before using header functions like `header()` or `setcookie()`. To solve this issue, use output buffering to capture any output before sending headers.

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

// Your PHP code here

ob_end_flush(); // Send output buffer