Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

http_response_code()

Read the current response status or set a new one.

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

Syntax

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

Read the current response status or set a new one. Setting a status returns the previous status if available. A CLI process initially has no web-server status, so querying it returns false and the first successful setter can return true. The default status of a web request is normally 200.

Signature

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

Example output

[false,true,202,204]

Examples

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

Result

[false,true,202,204]

Sources