- Display_errors = Off
- Error_reporting = E_ALL
By searching for these variables in the php. ini file, you can find the current default values of these two variables. The purpose of the display_errors variable is obvious-it tells PHP whether an error is displayed. The default value is Off. However, to make the development process easier, set this value to On:
- Display_errors = On
The default value of error_reporting variable is E_ALL. This setting displays all information from poor coding practices to harmless prompts to errors. E_ALL is a little too detailed for the development process, because it displays a prompt on the screen for some trivial matters (for example, the variable is not initialized), it will mess up the browser output. I only want to see errors and bad code practices, but do not want to see harmless prompts. Therefore, replace the default value of error_reporting with the following values:
- Error_reporting = E_ALL &~ E_NOTICE
Restart Apache and set all the settings. Next, we will learn how to do the same thing on Apache. 2. server error reports Depending on what Apache is doing, opening an error report in PHP may not work, because there may be multiple PHP versions on the computer. Sometimes it is difficult to tell which PHP version Apache is using, because Apache can only view one php. ini file. I don't know which php. ini file Apache is using to configure itself as a security issue. However, there is a way to configure the PHP variable in Apache to ensure that the correct error level is set. In addition, it is better to know how to set these configuration variables on the server side to reject or preemptible the php. ini file to provide higher-level security. When configuring Apache, you must have been exposed to the basic configuration in the http. conf file in/conf/httpd. conf. To add the following lines to httpd. conf to overwrite any php. ini file:
- Php_flag display_errors on
- Php_value error_reporting 2039
This overwrites the flag set for display_errors and the value of error_reporting in the php. ini file. The value 2039 represents E_ALL &~ E_NOTICE. If you want to use E_ALL, set the value to 2047. Similarly, restart Apache. Next, test the error report on the server. The error_reporting () function can shield some error messages, but the errors caused by the PHP core cannot be blocked, errors caused by PHP core will directly cause PHP file compilation failure, because the writing format is not written in accordance with PHP encoding rules, which cannot be blocked.
- * For now, avoid warnings of E_STRICT mode
- * (This must be done before function definitions)
- */
- If (defined ('e _ STRICT ')){
- $ Old_error_reporting = error_reporting (0 );
- If ($ old_error_reporting & E_STRICT ){
- Error_reporting ($ old_error_reporting ^ E_STRICT );
- } Else {
- Error_reporting ($ old_error_reporting );
- }
- Unset ($ old_error_reporting );
The following are common examples:
// Turn off all error reporting; disable all errors
- Error_reporting (0 );
// Report simple running errors; Report a simple running error
- Error_reporting (E_ERROR | E_WARNING | E_PARSE );
// Reporting E_NOTICE can be good too (to report uninitialized
- // Variables or catch variable name misspellings ...); Including reporting uninitialized variables or spelling errors for capturing variable names
- Error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE );
// Report all errors before T E_NOTICE
- // This is the default value set in php. ini; reports all errors but does not include E_NOTICE. This is also the default setting of php. ini.
- Error_reporting (E_ALL ^ E_NOTICE );
// Report all PHP errors (bitwise 63 may be used in PHP 3); Report all errors
- Error_reporting (E_ALL );
// Same as error_reporting (E_ALL); Same as above
- Ini_set ('error _ report', E_ALL );
|