headers_sent
Detect whether the HTTP header has been sent
headers_sent()
function checks whether the header has been sent/sent to where it is sent.
If no header is sent, send one:
<?php if ( ! headers_sent ( ) ) { header ( "Location: https://www.gitbox.net/" ) ; exit ; } ?> < html > < body > ... ...
Use optional file and line parameters:
<?php // Pass in $file and $line for subsequent use // Don't assign them in advance if ( ! headers_sent ( $file , $line ) ) { header ( "Location: https://www.gitbox.net/" ) ; exit ; // Error triggered here } else { echo "Headers sent in $file on line $line " ; exit ; } ?> < html > < body > ... ...
headers_sent ( file , line )
parameter | describe |
---|---|
file | Optional. If the file and line parameters are set, headers_sent() will place the PHP source file name and the line number at which the output starts in the file and line variables. |
line | Optional. Specifies the line number at which the output starts. |