Home:ALL Converter>Headers are being sent although output already sent

Headers are being sent although output already sent

Ask Time:2015-02-11T16:30:17         Author:Abhishek Agarwal

Json Formatter

For what I know is it is not possible to send HTTP headers after your output has been sent and only way to workaround is to use output buffering

But my PHP script is able to send headers even after output is sent. here is my code

Text output already sent
<?php
header('Location: test2.php');
die();
?>

Why is this code not giving error for "HTTP headers already sent" Is there another way to turn output buffering on?

EDIT:

I am running it on my localhost using wamp

No files are included in the above code

I just noticed outbut_buffering directive in phpinfo() which is set to 1 But when I check it in php.ini file it is set to Off

Author:Abhishek Agarwal,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28449713/headers-are-being-sent-although-output-already-sent
udondan :

You are right, this should not work.\n\nFirst, are you sure the headers are written, or do you simply wonder why there is no error message shown? Maybe error reporting is turned off? In that case try to increase the error reporting level:\n\nerror_reporting(E_ALL);\nini_set(\"display_errors\", 1);\n\n\nRemove this from your code when you're finished debugging. Errors should be logged to a log file and never be shown in productive environment!\n\nAlso, check if the header is really sent. You can do that with wget for example:\n\nwget -S http://example.com/\n\n\nor curl:\n\ncurl -v http://example.com/\n\n\nYou can as well see the HTTP headers in Chromes developer console. In other browsers most probably too.\n\nIf the header is really sent, then there probably is some magic regarding output buffering in place. Are you running this locally or on a remote host? If this is not your host, it might be the provider has set this up. PHP has a feature to automatically prepend and append custom code. Check the php.ini settings for auto_prepend_file and auto_append_file. There could be some ob_start() etc. hidden. You can see all PHP settings by calling phpinfo() or one specific with ini_get().",
2015-02-11T08:44:03
stepozer :

You don't see error because output buffering enabled. Try this code:\n\n<?php\nob_end_clean();\n?>\nText output already sent\n<?php\nheader('Location: test2.php');\ndie();\n?>\n\n\nIt return error:\n\n\n Text output already sent Warning: Cannot modify header information -\n headers already sent by\n",
2015-02-11T08:57:04
yy