PHP Security Programming: Do not let unrelated people see the error message

Source: Internet
Author: User
Tags php error php error reporting

There is no mistake developers, PHP error Reporting can help you to identify and locate these errors, can provide a detailed description of these errors, but if the malicious attackers see, this is not good. It is important not to let the public see the error message. It's easy to do this, as long as you close display_errors, of course, if you want to get an error message, you can open the Log_errors option and set the save path for the error log file in the Error_log option.

Because the level setting of the error report can cause some errors to be found, you need to set error_reporting to E_all at least. E_all | E_strict is the highest setting that provides backwards compatibility recommendations, such as tips that are not recommended for use.

All error reporting levels can be modified at any level, so if you are using a shared host and do not have permissions to make changes to php.ini, httpd.conf, or. htaccess profiles, you can run an error reporting level configuration statement in your program:

1 <?php
2
3 ini_set(‘error_reporting‘, E_ALL | E_STRICT);
4 ini_set(‘display_errors‘‘Off‘);
5 ini_set(‘log_errors‘‘On‘);
6 ini_set(‘error_log‘‘/usr/local/apache/logs/error_log‘);
7
8 ?>

Http://php.net/manual/ini.php provides a detailed description of the options configuration for php.ini.

Set_error_handler () function

PHP also allows you to specify your own error handling function through the Set_error_handler () function:

1 <?php
2 set_error_handler(‘my_error_handler‘);
3 ?>

The above program specifies your own error handling function, My_error_handler (). The following is an example of a practical use:

01 <?php
02
03 functionmy_error_handler($number$string$file$line$context)
04 {
05   $error"=  ==  ==  ==  ==\nPHP ERROR\n=  ==  ==  ==  ==\n";
06   $error.= "Number: [$number]\n";
07   $error.= "String: [$string]\n";
08   $error.= "File:   [$file]\n";
09   $error.= "Line:   [$line]\n";
10   $error.= "Context:\n". print_r($context, TRUE) . "\n\n";
11
12   error_log($error, 3, ‘/usr/local/apache/logs/error_log‘);
13 }
14
15 ?>

PHP 5 also allows the second parameter to be passed to Set_error_handler () to limit the execution of the defined error handling function in the event of an error. For example, now create a function that handles the alarm level (warning) Error:

1 <?php
2 set_error_handler(‘my_warning_handler‘, E_WARNING);
3 ?>

PHP5 also provides an exception handling mechanism, as described in Http://php.net/exceptions

PHP Security Programming: Do not let unrelated people see the error message

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.