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
- 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
function sendHeaders() {
echo 'Content-Type: text/html';
}
sendHeaders();
echo 'Hello World!';function sendHeaders() {
header('Content-Type: text/html');
}
sendHeaders();Fix for Cannot send headers. Output started at /var/www/html/index.php:123
Browse Related Clusters
Related PHP Errors
Undefined variable: user_id in /var/www/html/dashboard.php on line 25
Attempt to assign property of non-object in /var/www/html/controllers/
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Du
Notice: Trying to access array offset on value of type null in /var/ww
Related PHP Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error