Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php make the code return an error code when something goes wrong

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to return the error code when the code goes wrong with php". Many people will encounter this dilemma in the operation of the actual case, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php return an error code?

Using the header () function in php, you can add 404 header information to the returned page, thus reminding the browser that the page can not be found.

So you can use:

Header ("HTTP/1.0 404 Not Found")

Or:

Header ("Status: 404 Not Found")

The latter is used in FastCGI mode, and two sentences can be written directly at the same time in php code.

The instructions for using php on the official website of the excerpt header manual are as follows:

The header string.There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.For FastCGI you must use the following for a 404 response:

And header ("Location: xxx.com"); the default is to do 302 state jump, so it can not output 404 error status to the browser.

This is the end of the content of "how to make php return an error code when something goes wrong". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report