Home >Backend Development >PHP Tutorial >Modify php.ini to block error messages and record logs_PHP Tutorial
That's because the error display is turned off in php.ini and the errors are written into files. This is the result of artificial settings. Just display_errors =on.
However, it is safe to not display errors. It is recommended to turn it on during debugging and then turn it off when providing services.
Provide some information for you:
display_errors = On
php turns on error message display by default, we changed it to:
display_errors = Off
After turning off the error display, the PHP function execution error message will no longer be displayed to the user. This can prevent attackers from knowing the physical location of the script from the error message to a certain extent, as well as some other useful The information will at least cause certain obstacles to the attacker's black box detection. These error messages may be useful to ourselves. We can write it to the specified file, then modify the following:
log_errors = Off
to:
log_errors = On
and the specified file, find the following line:
;error_log = filename
Remove the previous; comment and change filename to the specified file, such as /usr/local/ apache/logs/php_error.log
error_log = /usr/local/apache/logs/php_error.log
In this way, all errors will be written to the php_error.log file.
======================================
error_reporting
Configure the level of error message reporting.
Syntax: int error_reporting(int [level]);
Return value: integer
Function type: PHP system function
This function is used to configure the level of error message reporting. The parameter level is An integer bitmask, see table below.
The mask value represents the name
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
E_NOTICE means not recording in general situations , is only used when there is an error in the program, such as trying to access a variable that does not exist, or calling the stat() function to view a file that does not exist.
E_WARNING is usually displayed but does not interrupt program execution. This is useful for debugging. For example: calling ereg() with the regular expression in question.
E_ERROR is usually displayed and will interrupt program execution. This means that memory configuration or other errors cannot be traced using this mask.
E_PARSE Parse error from syntax.
E_CORE_ERROR Like E_ERROR, but excludes errors caused by the PHP core.
E_CORE_WARNING Like E_WARNING, but does not include PHP core error warnings.
————————————
Extra:
1.
The 7 in
error_reporting(7) in the php file is 1+2+4, that is Return 1 E_ERROR 2 E_WARNING 4 E_PARSE
2.
php.ini
display_errors = Off //The default is to turn off error prompts
error_reporting = E_ALL //Display from bad coding practices to harmless prompts All error information, because the reported information is too detailed and includes harmless information, in order to see actual prompts during the development process, it is recommended to configure error_reporting = E_ALL & ~E_NOTICE