Frank
Frank

Reputation: 1864

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?

Upvotes: 46

Views: 185882

Answers (7)

Aditya P Bhatt
Aditya P Bhatt

Reputation: 22071

PHP has a configuration directive intended exactly for that, called display_errors. Like any other configuration setting, it's best to be set in php.ini. But in case you don't have access to this file, you can set it right in PHP code

to Hide All Errors:

ini_set('display_errors', 0);

to Show All Errors:

ini_set('display_errors', 1);

While ERROR_REPORTING value, which is often mistakenly taken responsible for hiding errors, should be kept at E_ALL all the time, so errors could be logged on the server.

Upvotes: 103

TimWolla
TimWolla

Reputation: 32701

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: ini_set('display_errors', 0);

Upvotes: 0

axiomer
axiomer

Reputation: 2126

In your php file just enter this code:

ini_set('display_errors', 0);

This will report no errors to the user. If you somehow want, then just comment this.

Upvotes: 4

john.w
john.w

Reputation: 343

Per the PHP documentation, put this at the top of your php scripts:

<?php ini_set('display_errors', 0); ?>

If you do hide your errors, which you should in a live environment, make sure that you are logging any errors somewhere. How do I log errors and warnings into a file? Otherwise, things will go wrong and you will have no idea why.

Upvotes: 11

Eskay Amadeus
Eskay Amadeus

Reputation: 318

You'd need to edit the php.ini file.

There is a section on Error handling and logging. You should carefully read it and then set your values.

If you want to indiscriminately hide all values, you can set error reporting to none:

error_reporting = ~E_ALL

Upvotes: -2

Dr Jay
Dr Jay

Reputation: 425

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

Upvotes: 3

Stewie
Stewie

Reputation: 3121

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

http://php.net/manual/en/book.errorfunc.php

Upvotes: 0

Related Questions