Page 1 of 1

override PHP warning page

Posted: Thu Jun 21, 2007 10:05 am
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

Posted: Thu Jun 21, 2007 10:11 am
by Gente

Posted: Thu Jun 21, 2007 10:22 am
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.

Posted: Thu Jun 21, 2007 10:22 am
by stereofrog
Well, the obvious solution would be to fix the problem. ;)

Posted: Thu Jun 21, 2007 10:36 am
by djot
-
Perhaps your webhotel allows you to set up your own error pages ... look into your webspaces' configuration.

djot
-

Posted: Thu Jun 21, 2007 11:16 am
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.