PHPCriticalRuntime ErrorJune 8, 2026

Runtime Error

Cannot modify header information - headers already sent in /var/www/html/index.php on line 50

What This Error Means

This error occurs when you're trying to send HTTP headers after output has already been sent to the browser. In PHP, headers must be sent before any output is generated.

Why It Happens

This error typically happens when there's a space or invisible character before the opening PHP tag, or when you're using functions like echo or print before sending headers. It can also occur when using output buffering, but not properly flushing it.

How to Fix It

  1. 1To fix this error, you need to ensure that no output is sent to the browser before sending headers. You can do this by removing any spaces or invisible characters before the opening PHP tag, or by using output buffering functions like ob_start() and ob_end_flush(). For example, if you're using header() function, place it before any output and ensure that no output is generated before it.

Example Code Solution

❌ Before (problematic code)
PHP
<?php
 // space here
 header('Location: login.php');
?>
✅ After (fixed code)
PHP
<?php
 ob_start();
 header('Location: login.php');
 ob_end_flush();
?>

Fix for Cannot modify header information - headers already sent in /var/www/html/index.php on line 50

Related PHP Errors

Related PHP Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error