what are the best practises for hiding all php errors? As I don't want ERRORS to show to the user.
I've tried using the .htacess
by putting the code php_flag display_errors off
in there, but it returns me a 500 error
.
Are there any other methods that will hide all errors?
to Hide All Errors:
error_reporting(0);
ini_set('display_errors', 0);
to Show All Errors:
error_reporting(E_ALL);
ini_set('display_errors', 1);
The best way is to build your script in a way it cannot create any errors! When there is something that can create a Notice or an Error there is something wrong with your script and the checking of variables and environment!
If you want to hide them anyway: error_reporting(0);
Use PHP error handling functions to handle errors. How you do it depends on your needs. This system will intercept all errors and forward it however you want it Or supress it if you ask it to do so
To hide errors only from users but displaying logs errors in apache log
error_reporting(E_ALL);
ini_set('display_errors', 0);
1 - Displaying error only in log
2 - hide from users
Per the PHP documentation, put this at the top of your php scripts:
<?php error_reporting(0); ?>
http://php.net/manual/en/function.error-reporting.php
If you do hide your errors, which you should in a live environment, make sure that you are logging any errors somewhere. How to log errors and warnings into a file? Otherwise, things will go wrong and you will have no idea why.
In your php file just enter this code:
error_reporting(0);
This will report no errors to the user. If you somehow want, then just comment this.
Source: Stackoverflow.com