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
You can also use PHP's error_reporting();
// Disable it all for current call
error_reporting(0);
If you want to ignore errors from one function only, you can prepend a @
symbol.
@any_function(); // Errors are ignored
Turn if off:
You can use error_reporting(); or put an @ in front of your fileopen().
Let me quickly summarize this for reference:
error_reporting() adapts the currently active setting for the default error handler.
Editing the error reporting ini options also changes the defaults.
Here it's imperative to edit the correct php.ini
version - it's typically /etc/php5/fpm/php.ini
on modern servers, /etc/php5/mod_php/php.ini
alternatively; while the CLI version has a distinct one.
Alternatively you can use depending on SAPI:
.htaccess
with php_flag
optionsphp.ini
.user.ini
Restarting the webserver as usual.
If your code is unwieldy and somehow resets these options elsewhere at runtime, then an alternative and quick way is to define a custom error handler that just slurps all notices/warnings/errors up:
set_error_handler(function(){});
Again, this is not advisable, just an alternative.
In file php.ini you should try this for all errors:
error_reporting = off
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');
In file php.ini you should try this for all errors:
display_errors = On
Location file is: