PHP Error Reporting and error message settings detailed

Source: Internet
Author: User
Tags ini php and php error php error reporting php web development php website

In the PHP website development, the error (Bugs) debugging and solves is the essential part, in the website debugging stage, the error message can give us the very big help, when the website on-line, we should also display the original error message in front of the user? The answer is no, in order to improve the user experience, we need to set the type and level of the PHP error report, the error message in a reasonable way to inform the user, but also to avoid providing malicious users with valuable information, such as file path, database information, and so on.

The following describes error reporting in PHP and how to set up error reporting.

  Error Reporting in PHP

You need to know a different type of error before you handle the error message, and click here to view it.

There are two main ways to set up error Reporting in PHP, either through the PHP configuration file php.ini, or by setting the type of the error report through the error_reporting () function, both to control the error level and to display the error message.

  Php. INI, how do I set the level of error reporting?

Open the php.ini file and find error_reporting = e_all & ~e_notice, which is the default error reporting setting, using a bitwise operation to indicate that all errors except E_notice are reported. If you do not want to display the WARNING information, the "" operator can be achieved by: error_reporting= E_all & ~ (E_notice e_warning).

  Error_reporting () function to set error reporting

The error reporting type set by this function overrides the error reporting settings in the profile php.ini file. This function argument can be in the form of a string or an integer. Like what

Error_reporting (3);

Equal to

Error_reporting ("E_error e_warning");

If you do not want to report any errors, you can do so by error_reporting (0).

Of course, as a PHP developer, in PHP Web development, you should set the error_reporting to E_all.

  Other

With the Phpinfo function, we can see the display_errors option, which can also set whether the error message is displayed to the user.

  Thoughts on the handling of error messages

After setting the type and level of error reporting, how do I handle error messages to improve the user experience?

In terms of program code, for insignificant errors, you can use @ To suppress errors, important error messages can be implemented through a custom error-handling function, the main use of the Set_error_handler function, PHP5 version can also be handled abnormally.

In front of the display, it is best not to display the original error message to the user, but should be through the page jump, artistic text information to inform the user.

The above is the basic introduction of error Reporting settings and error information processing in PHP.

  Note : PHP Web Development Tutorials-leapsoul.cn Copyright, reproduced in the form of links to indicate the original source and this statement, thank you.







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.