Home>Article>Backend Development> How to set http status code in php

How to set http status code in php

藏色散人
藏色散人 Original
2021-07-22 09:18:17 3574browse

php method to set http status code: first create a PHP sample file; then set the response HTTP status code through the "http_response_code(int $response_code = ?): mixed" method.

How to set http status code in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

phpHow to set http status code

php method to set http status code

http_response_code - Get/set the HTTP status code of the response

Description

http_response_code(int $response_code = ?): mixed

Get or set the HTTP status code of the response status code.

Parameters

response_code

The optional response_code will set the status code of the response.

Return value

If response_code is provided, the previous status code will be returned. If response_code is not provided, the current status code will be returned. In a web server environment, the default value for these status codes is 200.

If called in a non-Web server environment (such as a CLI application), if response_code is not provided, false will be returned. In a non-web server environment, providing response_code will return true (only if the status code has not been previously set).

Example

Example using http_response_code() in a Web server environment

The above routine will output:

int(200) int(404)

Recommended learning: "PHP Video tutorial

The above is the detailed content of How to set http status code in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn