KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / PHP

http_response_code()

Leest de responsstatus of stelt een nieuwe in.

Versie: PHP 8.4; repository runtime, production runtime not attested

Syntax

http_response_code(int $response_code = 0): int|bool

Leest de responsstatus of stelt een nieuwe in. Bij instellen komt de vorige status terug als die bestaat. Een nieuw CLI-proces heeft geen webserverstatus, dus uitlezen geeft false en de eerste instelling kan true geven. Een webverzoek begint normaal met 200.

Signatuur

http_response_code(int $response_code = 0): int|bool

Uitvoer van het voorbeeld

[false,true,202,204]

Voorbeelden

<?php
$initial=http_response_code(); $first=http_response_code(202); $previous=http_response_code(204);
echo json_encode([$initial,$first,$previous,http_response_code()]);

Resultaat

[false,true,202,204]

Bronnen