English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP tutorial

Advanced PHP tutorial

PHP & MySQL

PHP reference manual

PHP http_response_code () function usage and example

PHP HTTP  reference manual

The http_response_code () function gets/sets the HTTP response status code.

Syntax

int http_response_code ([ int $response_code ] )

Definition and usage

It is used to get or set the HTTP response

Return value

If response_code is provided, it will return the previous status code. If response_code is not provided, it will return the current status code. In the Web server environment, the default values for these status codes are all 200.
If response_code is not provided when called in a non-Web server environment (such as CLI applications), FALSE will be returned. In a non-Web server environment, providing response_code will return TRUE (only if the status code has not been set before).

Parameter

Serial numberParameters and descriptions
1

response_code

The optional response_code sets the response status code.

Online example

Try the following example

<?php
   var_dump(http_response_code());  
   http_response_code(404);
?>

The above code sets the response code to 404.

bool(false)

PHP HTTP  reference manual