tags:

views:

59

answers:

2

I've got a fairly general purpose PHP library which I'd like to use for a couple of different sites. The library serves up some content, but also detects error conditions, which is where my problems start. Trying to avoid redundant configuration, I've been attempting to get the server (or actually, been searching for documentation..) to serve up whatever error page it has configured, but haven't been able to come up with one single hint in either direction (possible or impossible). Maybe I'm not managing my search terms correctly, though.

Basically:

  1. Is it possible to redirect to the default error page of the current host from a PHP script?
  2. If not in general, is it possible with mod_php in Apache?
  3. If not, does anyone have another suggestion, how to solve the problem? :)

I don't have access to this particular piece of configuration (at least, not on all servers), so redundant configuration is not even possible in all cases.

Thanks!

A: 

To be honest with you, assuming this is PHP5, I wouldn't even try to redirect to an error page. If you are developing a library, and you encounter an error condition, throw an Exception.

Doing this, leaves it up to whomever consumes your library to deal with the error condition, whether it be log it, show an error, or crash hard.

Jordan S. Jones
+2  A: 

Well Jordan is right, your library should throw an exception. But in the code that consumes it, you can do a few thinks. All slightly hacky.

404 
header("Location: /some/nonexistantpath/you_want_to_show_the_user");

500
header("Location: /some/path/that/exists/and/has/a/php/error.php");

OR you can do an Apache sub request if you don't want the path to change on the user:

Virtual("..."); // see 500 and 404 notes above.
Byron Whitlock
I had no idea that Virtual command existed. Good call!
Matt