PHPCriticalRuntime ErrorApril 22, 2026

Runtime Error

Cannot send headers. Output started at /var/www/html/index.php:123

What This Error Means

This error occurs when PHP tries to send HTTP headers after the output has already started. In PHP, headers must be sent before any content is output.

Why It Happens

This error typically happens when PHP code attempts to output something before the headers have been sent. This could be due to echo statements, print statements, or even whitespace before the PHP opening tag. It can also occur when using functions that output data, like the var_dump() function.

How to Fix It

  1. 1To fix this error, you need to move any output-related code before sending the headers. This can be achieved by using the ob_start() function to turn on output buffering, or by moving echo statements and other output functions to the top of the script. Additionally, ensure that there are no whitespace characters before the PHP opening tag.

Example Code Solution

❌ Before (problematic code)
PHP
function sendHeaders() {
    echo 'Content-Type: text/html';
}
sendHeaders();
echo 'Hello World!';
✅ After (fixed code)
PHP
function sendHeaders() {
    header('Content-Type: text/html');
}
sendHeaders();

Fix for Cannot send headers. Output started at /var/www/html/index.php:123

Related PHP Errors

Related PHP Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error