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

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP http_response_code () function usage and example

PHP HTTP  Reference Manual

The http_response_code () function retrieves/Set 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 a Web server environment, the default values for these status codes are 200.
If called in a non-Web server environment (such as CLI applications), calling without response_code will return FALSE. In a non-Web server environment, providing response_code will return TRUE (only when the status code has not been set previously).

Parameter

NumberParameters and Description
1

response_code

The optional response_code will set the response status code.

Online Example

Try the following example

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

The following code will set the response code to404。

bool(false)

PHP HTTP  Reference Manual