Skip to content
PHP Logo

What is the significance of the error "Warning: Cannot modify header information" in PHP?

The error "Warning: Cannot modify header information" in PHP occurs when there is an attempt to modify header information after it has already been sent to the browser. This error often happens when there is whitespace or other output before the `header()` function is called. To solve this issue, make sure to call the `header()` function before any output is sent to the browser.

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

// Your PHP code here

// Example of setting a header
header("Location: https://www.example.com");

ob_end_flush(); // Flush the output buffer
?>