PHP Default Errors- How do I avoid showing these errors?

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
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

PHP Default Errors- How do I avoid showing these errors?

Post by danselstudios »

Hey PHP Devs,

This is one of the most recent errors I've come across:
Warning: copy(images/6.jpg) [function.copy]: failed to create stream: Permission denied in c:\websites\nickyscott120\nickyscott.com\cpanel\cpanel.php on line 19

An earlier error was about not being able to connect to my MySQL database.
Anyway, these problems of course were fixed. Now when these types of errors occur the result is white blank page with the exception of the ""Warning: copy....failed to create stream: c:..\cpanel.php on LINE 19."" message.

How do i prevent this default php error page from showing up and echo a custom error page.

Right Now I have something like this:

Code: Select all

$link = mysql_connect( $server, $loginame, $loginpass );
if( $link ){
         // do something;
}else{
        // $errors[] = 'Could not connect to host.';
}
Thanks in advance, Daniel M.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

You could do

Code: Select all

if (!<stuff goes here>)
{
// error stuff
}
The ! means "not", so you're saying if not <stuff> then do error stuff
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

That will still throw notices/warnings/errors if necessary. Try using @ before your function calls, although it's bad practice IMHO. What's wrong with the default PHP errors anyway?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Proper preparative execution and handling is the general "good" practice, as already mentioned.

set_error_handler() may be of interest too.
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

Post by danselstudios »

Well the default php error messages are just plain too long and UGLY.
So I'd like to handle the error messages myself so i may customize them to fit my website style.

I'll try set_error_handler() and @ before function calls.

thanks
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

Post by danselstudios »

jayshields or anyone,,, may you tell me a good website where i can find a glossary for stuff like the @ or . or -> or =>

or perhaps the name of the class or category where these things belong-thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

danselstudios wrote:jayshields or anyone,,, may you tell me a good website where i can find a glossary for stuff like the @ or . or -> or =>

or perhaps the name of the class or category where these things belong-thanks
Uhhh ... http://www.php.net/manual/
(#10850)
danselstudios
Forum Newbie
Posts: 24
Joined: Sat Jun 03, 2006 10:47 am
Location: Corona, CA

Post by danselstudios »

I can't anything on @ or => at php.net...I go there for everything else.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply