headers_sent

Checks if or where headers have been sent

Syntax

headers_sent ([ string &$file [, int &$line ]] ) : bool

Parameters

file

If the optional file and line parameters are set, headers_sent() will put the PHP source file name and line number where output started in the file and line variables.

line

The line number where the output started.

Return

headers_sent() will return FALSE if no HTTP headers have already been sent or TRUE otherwise.

Examples

1

<?

// If no headers are sent, send one
if (!headers_sent()) {
    header('Location: https://osbo.com/');
    exit;
}

// An example using the optional file and line parameters
// Note that $filename and $linenum are passed in for later use.
// Do not assign them values beforehand.
if (!headers_sent($filename, $linenum)) {
    header('Location: https://osbo.com/');
    exit;

// You would most likely trigger an error here.
} else {
    echo "Headers already sent in $filename on line $linenum\n" .
          "Cannot redirect, for now please click this <a " .
          "href=\"https://osbo.com\">link</a> instead\n";
    exit;
}

?>

			
		

PHP

Home Menu