The php Function Headers_Sent
The php function headers_sent checks if and where the HTTP headers have been sent. It is an important function to call before any output is sent, whether it be via a normal HTML tag or a blank line in a PHP file.
It can be helpful for debugging error messages or to see what the source of an exception is, especially if it is related to PHP parsing. It can be a bug in the underlying code or just an unintended consequence of how something is done, like a print statement or whitespace outside of PHP tags, which can cause the headers to be sent prematurely.
This is the function to call if you are getting errors related to the header() function, where you are getting a message that it has already been sent or that it is missing a value for one of its parameters. It can also help prevent some errors that would otherwise be triggered by the header() function, like when sending a Location header and continuing to parse the script after it has been redirected, which wastes system resources and may cause people to see pages they should not be seeing.
The parameters that can be passed into the headers_sent function are as follows. The replace parameter shows whether the present header should replace a previous similar-looking header or add a second header (default is True). The http_response_code is an optional field that forces additional headers of the same kind. The other two are a file name and a line number where the output started.