Menu Riverview Church

HEADER

Send a raw HTTP header

SYNTAX

header ( string $header [, bool $replace = TRUE [, int $http_response_code ]] ) : void

PARAMETERS

header

The header string.

There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.

<?

header("HTTP/1.0 404 Not Found");

?>

The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.

<?

header("Location: http://www.example.com/"); /* Redirect browser */

exit; /* Make sure that code below does not get executed when we redirect. */

?>
replace

The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type.

<?

header('WWW-Authenticate: Negotiate');header('WWW-Authenticate: NTLM', false);

?>
http_response_code

Forces the HTTP response code to the specified value. Note that this parameter only has an effect if the header is not empty.

RETURN

No value is returned.

EXAMPLES

1

Array
(
    [0] => X-Powered-By: PHP/7.4.9
    [1] => Content-Type: application/pdf
    [2] => Content-Disposition: attachment; filename="downloaded.pdf"
)

2

Array
(
    [0] => X-Powered-By: PHP/7.4.9
    [1] => Cache-Control: no-cache, must-revalidate
    [2] => Expires: Sat, 26 Jul 1997 05:00:00 GMT
)

PHP