Home > Backend Development > PHP Problem > How to close error message in php

How to close error message in php

PHPz
Release: 2023-04-12 17:33:31
Original
1826 people have browsed it

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:

  1. 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

  2. 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

  3. 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:

  1. Open the PHP code file and add a line of code as follows:

    error_reporting(0);

    Explanation: This code will report the error closure.

  2. 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:

  1. Open the .htaccess file and add the following code:

    php_flag display_errors off

  2. 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!

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