Home:ALL Converter>headers_sent() seems not working?

headers_sent() seems not working?

Ask Time:2018-03-05T21:32:05         Author:TechDogLover OR kiaNasirzadeh

Json Formatter

Important Note : output_buffering is off and I have checked it by get_ini() so please do not answer iteratives.

I have a simple php code:

<?php

in first step I will send a header, I also have write nothing before my php start tag and header is first:

header('Content-type: text/html; charset=utf-8');

now i want to be sure that my header has been sent so i use header_sent() function

if(!headers_sent()) {
    ?><script type="text/javascript">alert('No headers have been sent')</script><?php
} else {
    ?><script type="text/javascript">alert('headers have been sent')</script><?php
}
?>

Unfortunately I don't know why I will encountered with "No headers have been sent" while I expect headers have been sent.

Author:TechDogLover OR kiaNasirzadeh,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/49111629/headers-sent-seems-not-working
yy