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

How to set status code in php

青灯夜游
青灯夜游 Original
2021-03-18 17:33:58 4412browse

In PHP, you can use the http_response_code() function to set the status code. This function is used to set the HTTP status code of the response. The syntax format is "http_response_code (status code)".

How to set status code in php

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

php setting status code

http_response_code() function is used to get/set the HTTP status code of the response

Syntax:

http_response_code ($response_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:

The above routine will output:

int(200) int(404)

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set 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