Definition and Usage
http_response_code - Get / Set response HTTP status code
Version Support
PHP4 | php5 | PHP7 |
---|---|---|
not support | stand by | stand by |
grammar
http_response_code ([ int $response_code ] )
Gets or sets the HTTP status code of the response.
parameter
parameter | Necessary | description |
---|---|---|
response_code | no | Optional response_code response status code is set. |
return value
If a response_code, it will return to its previous state code. If no response_code, returns the current status code. In the Web server environment, the default values of these status codes are 200. If you call (CLI applications such as Lane) in non-Web server environment, do not provide response_code will return FALSE. In non-Web server environment, providing response_code returns TRUE (only when the state has not been set in the previous code).
Examples
// Get the current status code, and set the new status code var_dump(http_response_code(404)); // Get the new status code var_dump(http_response_code());
related functions
headers_list () - returns the HTTP response headers sent (or ready to send)
header () - Send native HTTP header are discussed in more detail.