English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The headers_sent() function detects whether the HTTP header has been sent.
bool headers_sent ([ string &$file [, int &$line ]])
Detect 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 prevents 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 Description |
---|---|
1 | file If optional parameters file and line are set, headers_sent() will put the PHP file name in the file variable, and output 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: \//www.oldtoolbag.com/'); exit; } header('Location: \//www.oldtoolbag.com/'); exit; } else { echo \ "href = \//www.oldtoolbag.com\">link</a> instead "; exit; } ?>
The above example checks if the header has been sent. If it has been sent, a message is displayed; otherwise, the header is sent.