Current Location: Home> Function Categories> headers_sent

headers_sent

Detect whether the HTTP header has been sent
Name:headers_sent
Category:Network
Programming Language:php
One-line Description:Check if/where the header has been sent.

Definition and usage

headers_sent() function checks whether the header has been sent/sent to where it is sent.

Example

Example 1

If no header is sent, send one:

 <?php
if ( ! headers_sent ( ) ) {
  header ( "Location: https://www.gitbox.net/" ) ;
  exit ;
}
?>

< html >
< body >

...
...

Example 2

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 >

...
...

grammar

 headers_sent ( file , line )

Parameter value

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.
Similar Functions
Popular Articles