English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The headers_sent() function checks if the HTTP header has been sent.
bool headers_sent ([ string &$file [, int &$line ]])
Check if the HTTP header has been sent.
When the HTTP header has been sent, it is not possible to add more header fields through header(). Using this function at least can prevent HTTP header errors. Another solution is to use output buffering.
When the HTTP header has not been sent, headers_sent() returns FALSE, otherwise it returns TRUE.
Number | Parameters and descriptions |
---|---|
1 | file If the optional parameters file and line are set, headers_sent() will put the PHP file name in the file variable, and the starting line number in the line variable. |
2 | line Output the starting line number. |
Try the following example
<?php if (!headers_sent()) { header('Location: http://ru.oldtoolbag.com/'); exit; } if (!headers_sent($filename, $linenum)) { header('Location: http://ru.oldtoolbag.com/'); exit; } else { echo \ "href = \ exit; } ?>
The following example checks if the header has been sent, if it has been sent, a message is displayed, otherwise the header is sent