headers_sent() return false, but headers were sent

html, http-headers, php

Solution

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!

Problem

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.

Original source