24/7 U.S. Support – 877-595-4482
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:
echo " THIS IS A TEST ";
In example 2, we have two files:
// do something here, such as validate a login attempt
// 2.php validates the user and checks if they logged in successfully
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|
|Chat:||Click To Chat Now|