How to hide fuction errors from client-side?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DavidDC
Forum Newbie
Posts: 3
Joined: Mon Jun 12, 2006 3:18 pm

How to hide fuction errors from client-side?

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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!
DavidDC
Forum Newbie
Posts: 3
Joined: Mon Jun 12, 2006 3:18 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
DavidDC
Forum Newbie
Posts: 3
Joined: Mon Jun 12, 2006 3:18 pm

Post by DavidDC »

feyd,

thanks for your confirmation.

chris,

thanks for your first input that triggered my exploration.

-david
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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
?>
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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!
Post Reply