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:
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‘ ); |
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:
2 |
set_error_handler( ‘my_error_handler‘ ); |
The above program specifies your own error handling function, My_error_handler (). The following is an example of a practical use:
03 |
function my_error_handler( $number , $string , $file , $line , $context ) |
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" ; |
12 |
error_log ( $error , 3, ‘/usr/local/apache/logs/error_log‘ ); |
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:
2 |
set_error_handler( ‘my_warning_handler‘ , E_WARNING); |
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