The headers_sent() function checks if/where HTTP headers are sent.
This function returns TRUE if the header has been sent, FALSE otherwise.
headers_sent(file,line)
parameter | describe |
---|---|
file,line | Optional. If the file and line parameters are set, headers_sent() will store the PHP source file name and line number where the output starts into the file and line variables. |
Note: Once a header block has been sent, you cannot use the header() function to send additional headers.
Note: The optional file and line parameters are new in PHP 4.3.
<?php// If no headers are sent, send oneif (!headers_sent()) { header("Location: http://www.w3cschool.cc/"); exit; }?><html><body>. .....
Use the optional file and line arguments:
<?php// $file and $line are passed in for later use// Do not assign them values beforehandif (!headers_sent($file, $line)) { header("Location: http://www.w3cschool.cc /"); exit; // Trigger an error here }else { echo "Headers sent in $file on line $line"; exit; }?><html><body>......