header()

header() — Send a raw HTTP header.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

header() is used to send a raw HTTP header. See the HTTP/1.1 specification for more information on HTTP headers.

Signature

header(string $header, bool $replace = true, int $response_code = 0): void

Parameters

ParameterTypeWhat it takes
$headerstringThe header string.
$replaceboolThe 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. For example:
$response_codeintForces the HTTP response code to the specified value. Note that this parameter only has an effect if the header is not empty.

Return value

No value is returned.

Example

A runnable snippet:

// We'll be outputting a PDF header('Content-Type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf');

See also

headers_sent(), setcookie(), http_response_code(), header_remove(), headers_list()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page header() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.