Page 1 of 1

How to hide fuction errors from client-side?

Posted: Mon Jun 12, 2006 3:41 pm
by DavidDC
Hi,

I am still learning PhP. Cannot figure out how to hide error information from
showing up on the client side.

I have a Php file, which uses the function file_get_contents($url) to collect
data from another web site. Sometimes, the function call cannot succeed and
geneates error messages displayed on client-side distorting nicely laid-out pages.
I dont want any error messages to display on client side. I used the following
but it still displays error messages on the client side.

$html = file_get_contents($url) or die("");

How can I do it?

Forgive me if this is a stupid question.

Regards.

Posted: Mon Jun 12, 2006 3:45 pm
by tecktalkcm0391
just put this on the top of everypage

Code: Select all

error_reporting(0);
I'm pretty sure that would do the job!

Posted: Mon Jun 12, 2006 3:57 pm
by DavidDC
Chris,

Thanks for your input. I started with your input and did some research and hope
to find a new way. In the php.ini file, I now change the value from On to Off
for the following parameter:

display_errors = Off

Could you please tell me whether the above will achieve the same results
as your solution?

In your suggestion, you used

error_reporting(0)

What constant corresponds to the value 0?
see http://us2.php.net/error_reporting. I am using php 5.0.4.

Do you think the php.ini solution may be better than putting
error_reporting(0) on every page?

Once again, thanks very much!

-David

Posted: Mon Jun 12, 2006 4:05 pm
by feyd
display_errors is a "better" solution than turning off error_reporting. Either do it in php.ini or in an .htaccess or whatever local level your web server supports. Setting it in a script does not block parse errors from being displayed.

Posted: Mon Jun 12, 2006 4:14 pm
by DavidDC
feyd,

thanks for your confirmation.

chris,

thanks for your first input that triggered my exploration.

-david

Posted: Mon Jun 12, 2006 4:33 pm
by RobertGonzalez
There are two directives that you could use to hide errors completely: error_reporting and display_errors. For local development I have error_reporting set to E_ALL (which reports absolutely everything that is not kosher with the script) and display_errors set to On. On my production servers I have error_reporting set to whatever level is necessary to maintain the site, but I almost always have display_errors set to Off. This is mainly for security and not so much for aesthetics.

These values can be set/changed at runtime with a call to ini_set...

Code: Select all

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true); // or false to turn them off
?>

Posted: Mon Jun 12, 2006 6:04 pm
by tecktalkcm0391
Yeah, I don't have my own server so i've nevered been in the php.inc, but doing what feyd said would be best!