In actual development, PHP's error report is usually a very useful tool that can help developers quickly locate the problem. However, in some cases, developers may want to turn off PHP error reporting, such as when releasing the application to a production environment and do not want sensitive information to be disclosed.
Below, we will introduce how to turn off PHP error reporting.
Method 1: Modify the PHP.ini file
In the PHP.ini file, you can turn off PHP's error reporting by modifying the parameter error_reporting. The steps are as follows:
Find the PHP.ini file. In Linux systems, it is usually stored in the /etc directory and can be found through the command line. For example, enter the following command:
find / -name php.ini
Find the error_reporting parameter and change its value to 0. In PHP.ini files, this parameter is usually located at the bottom of the document.
error_reporting = 0
Save and close the PHP.ini file.
Description: This method is suitable for turning off all error reports globally.
Method 2: Turn off reporting in PHP code
In PHP code, you can turn off error reporting by setting the parameters of the function error_reporting(). The steps are as follows:
Open the PHP code file and add a line of code as follows:
error_reporting(0);
Explanation: This code will report the error closure.
Save the file and upload it to the web server.
Note: This method will only affect the current script and will not affect the entire application.
Method 3: Modify the .htaccess file
If you are using the Apache server, you can turn off PHP's error reporting by adding the following code to the .htaccess file . The steps are as follows:
Open the .htaccess file and add the following code:
php_flag display_errors off
Save the file and upload it to on the web server.
Note: This method will only affect PHP files in the current directory and subdirectories.
Summary
In actual development, although turning off PHP error reporting may increase the difficulty of development, it also has its application scenarios. Whichever method you choose to turn off error reporting in PHP, always decide carefully and make sure all error messages are handled correctly.
The above is the detailed content of How to close error message in php. For more information, please follow other related articles on the PHP Chinese website!