Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php hide ALL errors

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?

like image 671
Frank Avatar asked Feb 11 '12 18:02

Frank


People also ask

Can we hide errors in PHP?

To turn off or disable error reporting in PHP, set the value to zero.

How do I hide warnings and notices in PHP?

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.

How do I show all errors in PHP?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);


2 Answers

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); 
like image 64
Aditya P Bhatt Avatar answered Sep 23 '22 06:09

Aditya P Bhatt


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.

like image 29
john.w Avatar answered Sep 20 '22 06:09

john.w