PHP Turn On or Off Error Reporting

How to turn on or off Error reporting with PHP
Error reporting is useful for debugging purposes. As well, perhaps you have some unimportant PHP warning displaying on your website that you would like to remove. This article will show you how to both display and hide PHP errors and warnings from the user.

PHP Code to Display All Errors and Warning Messages

To display all warnings and notice this is an easy and simple way that should work in most hosting environments:

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

PHP Code to Turn See Warning Messages and Not Notices

ini_set('display_errors',1);
error_reporting(E_ALL);

PHP Code to Turn Off Error Reporting

error_reporting(0);

or

ini_set('display_errors',0);
error_reporting(E_ALL|E_STRICT);

Where to Place Code to Remove Errors and Warnings

You can place the bits of code above just about anywhere on in your PHP code but it has to be above the error or else you will not see any warnings or notices since the code is read from the top down.

Tip for WordPress Users: Place Code in Your wp-config.php File

To turn on or off error reporting site-wide then place the the lines of code above all other PHP in your WordPress site’s wp-config.php file located in your home directory.

PHP Error Reporting Via .htaccess File

If you prefer to use your .htaccess file then you can use the following code to display errors.

php_flag display_errors on
php_value error_reporting 7

One thought on “PHP Turn On or Off Error Reporting

Leave a Reply

Your email address will not be published. Required fields are marked *