Alex Alex - 16 days ago 7
HTML Question

headers_sent() return false, but headers were sent

My code is simple:

<!DOCTYPE html>
<html>
<head>
...

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


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

Answer

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!

Comments