Check if content has been submitted in PHP

Is there any reasonable way to check if the output has already been sent to the browser and sending the header will create PHP_WARNING?

Obviously, there is an alternative to using the output buffer, but this is not always an option.

+3
source share
4 answers

You can use the headers_sent () method. This is because, before anything comes out, headers will be sent first.

+6
source
if (headers_sent())
{
    trigger_error("Here you got your warning", E_WARNING);
}
+2
source
+1

, :

$old_er = error_reporting(0);

header(...)

error_reporting($old_er);

PHP- ( , IMO).

-1

Source: https://habr.com/ru/post/1706583/


All Articles