How to close php error prompt? Sharing methods between the two

PHPz
Release: 2023-04-11 13:26:02
Original
1403 people have browsed it

PHP programmers often encounter various errors during the development process. In order to facilitate error checking, PHP will output error prompts by default. But in a production environment, these error messages may not only expose your code structure, but also affect the performance and security of the website. Therefore, turning off PHP error messages is a necessary and simple operation.

Next we will discuss in detail how to turn off PHP error prompts.

The first way to close: modify the php.ini file

In the PHP installation directory, there is a configuration file named "php.ini" . This file records various configuration information of PHP, including error message information. We can turn off PHP error prompts by modifying the relevant configuration in this file.

Step 1: Find the php.ini file

First you need to find the php.ini file. Generally, in the PHP installation directory, there will be a file named "php.ini". If you can't find it, you can enter php --ini on the command line to view PHP information, including the path to the php.ini file.

Step 2: Modify the php.ini file

Use a text editor to open the php.ini file and find the following two lines of code:

display_errors = On
error_reporting = E_ALL
Copy after login

Change "On" is changed to "Off", which means turning off the error prompt. At the same time, change "E_ALL" to "0" to turn off all error reporting. The modified code is as follows:

display_errors = Off
error_reporting = 0
Copy after login

Save the changes and exit the editor.

Step 3: Restart PHP

After modifying the php.ini file, you need to restart PHP for the settings to take effect. You can enter sudo service php7.2-fpm restart on the command line to restart Apache or Nginx to make the new php.ini configuration take effect.

Second closing method: Add code in the PHP file

In some cases, we may not have permission to modify the php.ini file. At this time, we can turn off PHP error prompts by adding code to the PHP file.

Add the following code at the beginning of the PHP file that needs to turn off error prompts:

ini_set('display_errors', 'Off');
error_reporting(0);
Copy after login

In this way, we turn off error prompts in the development environment, protecting the security of the code and Improved website performance.

However, it is recommended to use log files to record error information in a production environment so that subsequent errors can be analyzed and the program can be improved.

The above is the detailed content of How to close php error prompt? Sharing methods between the two. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!