I am trying to turn off all errors on my website. I have followed different tutorials on how to do this, but I keep getting read and open error messages. Is there something I am missing?
I have tried the following in my php.ini file:
;Error display display_startup_errors = Off display_errors = Off html_errors = Off docref_root = 0 docref_ext = 0
For some reason when I do a fileopen() call for a file which does not exist, I still get the error displayed. This is not safe for a live website, for obvious reasons.
In the current file, search for the line of code error_reporting. There will be a line of Default Value: E_ALL as shown below: Replace this line of code with Default Value: E_ALL & ~E_NOTICE. It will display all the errors except for the notices.
By default, PHP sends an error log to the server's logging system or a file, depending on how the error_log configuration is set in the php. ini file. By using the error_log() function you can send error logs to a specified file or a remote destination.
Enable Error Logging in php. If you want to enable PHP error logging in individual files, add this code at the top of the PHP file. ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Now, you must enable only one statement to parse the log errors in the php.
I always use something like this in a configuration file:
// Toggle this to change the setting define('DEBUG', true); // You want all errors to be triggered error_reporting(E_ALL); if(DEBUG == true) { // You're developing, so you want all errors to be shown display_errors(true); // Logging is usually overkill during development log_errors(false); } else { // You don't want to display errors on a production environment display_errors(false); // You definitely want to log any occurring log_errors(true); }
This allows easy toggling between debug settings. You can improve this further by checking on which server the code is running (development, test, acceptance, and production) and change your settings accordingly.
Note that no errors will be logged if error_reporting is set to 0, as cleverly remarked by Korri.
You should consider not displaying your error messages instead!
Set ini_set('display_errors', 'Off');
in your PHP code (or directly into your ini file if possible), and leave error_reporting on E_ALL
or whatever kind of messages you would like to find in your logs.
This way you can handle errors later, while your users still don't see them.
define('DEBUG', true); error_reporting(E_ALL); if (DEBUG) { ini_set('display_errors', 'On'); } else { ini_set('display_errors', 'Off'); }
define('DEBUG', true); error_reporting(E_ALL); ini_set('display_errors', DEBUG ? 'On' : 'Off');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With