Signatur
header(string $header, bool $replace = true, int $response_code = 0): void
Beschreibung
Für JSON-Responses, Redirects, Cache-Control, Content-Security-Policy.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $header Pflicht | string | — | Header-Zeile. |
| $replace | bool | true | Existierende Header überschreiben. |
| $response_code | int | 0 | HTTP-Statuscode. |
Rückgabewert
Typ
void
Beschreibung
Nichts.
Beispiele
JSON-Response
<?php
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['ok' => true]);
Redirect
<?php
header('Location: /login', response_code: 302);
exit;