php error message configuration

WBOY
Release: 2016-07-29 09:15:25
Original
1207 people have browsed it

Error echo is commonly used in development mode, but many applications forget to turn off this option in the official environment. Error echo can expose a lot of sensitive information, which facilitates the attacker's next attack. It is recommended to turn off this option

display_errors
Error echo, commonly used in development mode, but many applications forget to turn off this option in the formal environment. Error echo can expose a lot of sensitive information, which facilitates the attacker's next attack. It is recommended to turn this option off.
display_errors = On
In the on state, if an error occurs, an error will be reported and an error message will appear.
dispaly_errors = Off
In the off state, if an error occurs, it will prompt: Server error. But no error message will appear.
log_errors
Just use this in a formal environment and record the error information in the log. Just in time to turn off error echo.
For PHP developers, once a product is put into use, the first thing to do is to turn off the display_errors option to avoid being attacked by hackers due to the paths, database connections, data tables and other information disclosed by these errors.
After a product is put into use, there will inevitably be error messages, so how to record this information that is very useful to developers?
Just turn on PHP's log_errors. By default, it is recorded to the log file of the WEB server, such as Apache's error.log file.
Of course, you can also record error logs to specified files.

# vim /etc/php.inidisplay_errors = Off
log_errors = On
error_log = /var/log/php-error.log

You can also set error_log = syslog to record these error messages to the operating system log inside.
display_errors = Off //display in Chinese means display, so display_error=off means not displaying errors!
error_reporting sets the level of error message reporting
2047 I remember it should be E_ALL.
php.ini There are many configuration settings in the file. You should have already set up your php.ini file and placed it in the appropriate directory, just like installing PHP and Apache on Linux 2 (see Resources). There are two configuration variables that you should be aware of when debugging PHP applications. The following are these two variables and their default values:
display_errors = Off //Turn off all error messages. When it is ON, all error messages are displayed.
error_reporting = E_ALL
E_ALL covers everything from bad coding practices to harmless tips to errors. E_ALL is a bit too detailed for the development process, because it also displays prompts on the screen for small things (such as variables not being initialized), which will mess up the browser's output
So it is not recommended to use 2047, it is best to change the default value to: error_reporting = E_ALL & ~E_NOTICE
Solution to the failure of display_errors = Off in PHP.ini
Problem:
Display_errors = Off has been clearly set in the PHP setting file php.ini, but during operation, error messages still appear on the web page.
Solution:
Check log_errors= On, according to the official statement, when this log_errors is set to On, then the error_log file must be specified. If it is not specified or the specified file does not have permission to write, then the error will still occur. Out of the normal output channel, this also invalidates the specified Off of display_errors, and the error message is still printed. So log_errors = Off, the problem is solved.
It is often seen that error_reporting (7) means: setting the level of error message reporting.
value constant
1 E_ERROR
2 E_WARNING
4 E_PARSE
8 E_NOTICE
16 E_CORE_ERROR
32 E_CORE_WARNING
64 E_COMPILE_ERROR
128 E_COMPILE_WARNING
256 E_USER_ ERROR
512 E_USER_WARNING
1024 E_USER_NOTICE
2047 E_ALL
2048 E_STRICT
However, 7=1+2+ 4
It means 1 E_ERROR 2 E_WARNING 4 E_PARSE

//Disable error reporting
error_reporting(0);
//Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting all errors
error_reporting(E_ALL);
?>

The above introduces the PHP error message configuration, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template