Skip to content
PHP Logo

What is causing the "Cannot modify header information" error in PHP?

The "Cannot modify header information" error in PHP occurs when there is an attempt to modify header information after it has already been sent to the browser. To solve this issue, ensure that there is no output (such as HTML, text, or whitespace) before calling functions like header() or setcookie().

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

// Your PHP code here

ob_end_flush(); // End output buffering and flush the output
?>