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)".
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:
<?php // 获取当前状态码,并设置新的状态码 var_dump(http_response_code(404)); //获取新的状态码 var_dump(http_response_code()); ?>
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
