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 to shield all errors in php.ini

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

Share

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

This article mainly shows you "how to shield all errors in php.ini". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to shield all errors in php.ini".

The method of shielding all errors in php.ini: 1, open the "php.ini" configuration file and search for the "display_errors" entry; 2, set the value of the "display_errors" item to "Off" to turn off all PHP error reports, thereby shielding all errors.

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

The way to shield all errors in php.ini:

Open the php.ini configuration file, search for display_errors, and then set the value of display_errors to Off to turn off all PHP error reporting. As follows:

; This directive controls whether or not and where PHP will output errors,; notices and warnings too. Error output is very useful during development, but; it could be very dangerous in production environments. Depending on the code; which is triggering the error, sensitive information could potentially leak; out of your application such as database usernames and passwords or worse.; For production environments, we recommend logging errors rather than; sending them to STDOUT.; Possible Values:; Off = Do not display any errors; stderr = Display errors to STDERR (affects only CGI/CLI binaries!); On or stdout = Display errors to STDOUT; Default Value: On; Development Value: On; Production Value: Off; http://php.net/display-errorsdisplay_errors = Off

This approach should be the most thorough solution, because it works on all PHP files.

Extended knowledge: other ways to shield errors

Use the error control operator: @

PHP supports the use of the error control operator @. Any error messages that may be generated by an PHP expression will be ignored before it is placed.

If you set a custom error handler with set_error_handler (), the error handler will still be called, and if @ is used before the error statement, the error handler will return 0.

It is important to note that the @ operator is valid only for expressions. To put it simply, if you can get a value from somewhere, you can precede it with the @ operator. For example, you can use the @ operator before variables, functions, include calls, constants, and so on, but it cannot be placed before the definition of a function or class, nor can it be used before conditional structures such as if and foreach statements.

The @ operator is also valid for serious errors that can cause the program to terminate, which means that if @ is used to suppress the error message before a function call that does not exist or typed the wrong letter, the program will die there without any hint.

[example] use the @ error operator to mask errors in the code.

The running results are as follows:

Database connection failed! The above is all the contents of the article "how to block all errors in php.ini". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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