override PHP warning page

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
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

override PHP warning page

Post by aceconcepts »

Hi,

If I have a link to a file that does not exist and the user clicks it, the following message will appear:

Warning: main(pages/script.php) [function.main]: failed to open stream: No such file or directory in /home/site/public_html/index.php on line 163

How can I display a friendlier message or redirect the user instead of having this techy message appear?

Thanks
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

In your place i would check if file exists before trying to open it, because these error messages will be bad for performance.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Well, the obvious solution would be to fix the problem. ;)
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Perhaps your webhotel allows you to set up your own error pages ... look into your webspaces' configuration.

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

Post by RobertGonzalez »

Simplest way possible:

Code: Select all

<?php
if (!file_exists($filename))
{
  echo 'This is my own custom error message, made just by yours truly.';
  // Maybe even exit at this point, if you want to prevent further processing.
}
else
{
  // carry on.
}
?>
Always always always check for possible errors and catch them when you possibly can.
Post Reply