Web Hosting Talk







View Full Version : custom error pages (in php)


MGCJerry
10-31-2002, 08:46 PM
I'm working on some custom error pages I'm wanting to fully integrate into my phpnuke site, but I'm having a little problems.

I added the following in my htaccess file:

##
## Error Documents
##
ErrorDocument 400 /errordocs.php?e=400
ErrorDocument 401 /errordocs.php?e=401
ErrorDocument 403 /errordocs.php?e=403
ErrorDocument 404 /errordocs.php?e=404


The script works fine when the failed request is for a file in the document root. Example: http://localhost/nosuch.file displayes the error page correctly, but when a file in a directory like http://localhost/somedirectory/nosuch.file and my images, and CSS doesnt show up.

Here is my php code:


include("mainfile.php");
include("header.php");

if ($e == "400") {
$errortitle ="Bad Request";
$errormsg ="page text";
} elseif ($e == "401") {
$errortitle ="AUnauthorized!";
$errormsg ="page text";
} elseif ($e == "403") {
$errortitle ="Forbidden!";
$errormsg ="page text";
} elseif ($e == "404") {
$errortitle ="File Not found!";
$errormsg ="page text";
} else {
$errortitle ="An Error has Occurred";
$errormsg ="page text";
}

OpenTable();
echo "<center><font class=\"title\">$errortitle</font></center>";
CloseTable();
echo "<br>";

OpenTable();
echo "$errormsg";
CloseTable();

include("footer.php");

?>


Hopefully I made a little sense :)

Thanks in advance.

iamdave
10-31-2002, 11:06 PM
Use <base href="http://yoursite.com"> in the <HEAD> section of your code, this way all images and css will work.

MGCJerry
11-01-2002, 10:09 AM
Thanks, it works great :)

iamdave
11-01-2002, 09:12 PM
Originally posted by MGCJerry
Thanks, it works great :) :)