Alex Alex - 1 year ago 70
HTML Question

headers_sent() return false, but headers were sent

My code is simple:

<!DOCTYPE html>

<?php var_dump(headers_sent()); ?>

It returns false. Shouldn't the headers be sent immediately after something is printed? Like just after the first

Answer Source

It depends if your output_buffering directive in php.ini file. If it is Off

output_buffering = Off

then echo headers_sent() should output 1

In other cases, headers_sent() won't output any results because it will be FALSE. The headers won't be sent because the output is buffered.

If you want to get around this and force-send headers, you can use flush().

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download