You generally receive a:
Cannot modify header information - headers already sent by...
when a php script returns output to the screen (such as html code) and then tries to modify any of the header information. Headers should always be sent before any other ouput (such as html), and php will throw an error message if headers are sent after any other data is sent.
In this article, we'll provide two generic examples to show what is happening.
THIS IS A TEST
Warning: Cannot modify header information - headers already sent by (output started at /home/whhsup5/public_html/projects/cannot-modify-headers/1.php:4) in /home/whhsup5/public_html/projects/cannot-modify-headers/1.php on line 6
As you can see, "THIS IS A TEST" printed to the screen, and the error occurred after we then attemped to modify the header information using the header function on the next line. To resolve this issue, the header function call should be made first:
header("Location:http://www.webhostinghub.com/support");
echo " THIS IS A TEST ";
In example 2, we have two files:
<?php
// do something here, such as validate a login attempt
?>
<?php
// 2.php validates the user and checks if they logged in successfully
include_once("2.php");
header("Status: 403 Forbidden");
echo "<h1>This is custom 403 test page</h1>";
?>
In this example, 2.php includes the logic that would validate a login attempt, and 3.php would take action. It is a very simply
Email: | support@WebHostingHub.com | Ticket: | Submit a Support Ticket |
---|---|---|---|
Call: | 757-416-6627 | Chat: | Click To Chat Now |
We value your feedback!
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
new! - Enter your name and email address above and we will post your feedback in the comments on this page!