Free web development scripts for the webmasterDevelopment Scripts


 social media marketing services
 Site Navigation
Clicky Web Analytics
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o PHP
   o Miscellaneous
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Paper Free Invoicing
 o Tutorials
 o Expired Domain Crawler

Dynamic Error Pages (Rated 5)

Description:

A dynamic PHP script which returns different error messages depending on the error received. The script will also send an e-mail to your e-mail address with the time, error received, requested page and the page they came from. (Optional).

(Please note: To use this script you need to be allowed use custom error pages on your host.)

How To Install The Script:

* Copy and paste the below script into your page where you would like your error to be displayed.
* Change the "error@example.com" e-mail below to your e-mail address.
* Add the following lines to your .htaccess file (change the location of your error page, if needed):
ErrorDocument 400 /errorpages/errorpage.php?error=400
ErrorDocument 401 /errorpages/errorpage.php?error=401
ErrorDocument 403 /errorpages/errorpage.php?error=403
ErrorDocument 404 /errorpages/errorpage.php?error=404
ErrorDocument 500 /errorpages/errorpage.php?error=500
* And it's as simple as that!

Code starts here


<?php
/*
Dynamic Error Pages v1.01

Copyright (c) 2004 Sabre Web Design <http://www.sabrewebdesign.com/>
All rights reserved.

If you like this script, we would appreciate a link back to Sabre Web Design <www.sabrewebdesign.com>.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Redistributions of this script is free for Non-Commercial use ONLY!
* Neither the name of Sabre Web Design nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

HOW TO INSTALL THE SCRIPT:
* Copy and paste this whole script into your page where you would like your error to be displayed.
* Change the "error@example.com" e-mail below to your e-mail address.
* Add the following lines to your .htaccess file (change the location of your error page, if needed):
ErrorDocument 400 /errorpages/errorpage.php?error=400
ErrorDocument 401 /errorpages/errorpage.php?error=401
ErrorDocument 403 /errorpages/errorpage.php?error=403
ErrorDocument 404 /errorpages/errorpage.php?error=404
ErrorDocument 500 /errorpages/errorpage.php?error=500
* And it's as simple as that!

*/

//Find error code
$error=$_GET['error'];

//E-mail to be used for errors (Change this to your email address)
$email = "error@example.com";

//Find reffering and requested URLs
$referring_url = $_SERVER['HTTP_REFERER'];
$requested_url = $_SERVER["REQUEST_URI"];

//Different error messages to display
switch ($_REQUEST['error']) {

//Error 400 - Bad Request
case 400:
$errorname = 'Error 400 - Bad Request';
$errordesc = '<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">Bad Request</FONT></B><FONT face="Verdana, Arial, Helvetica, sans-serif" size="2"><BR>
Error 400<BR>
<BR>
The URL that you requested, was a bad request. <BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'
."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach. We are sorry for any inconvenience caused and we will do all we
can to fix the error as soon as possible.</FONT>'
;
break;


//Error 401 - Authorization Required
case 401:
$errorname = 'Error 401 - Authorization Required';
$errordesc = '<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">Authorization
Required</FONT></B><FONT face="Verdana, Arial, Helvetica, sans-serif" size="2"><BR>
Error 401<BR>
<BR>
The URL that you requested, requires preauthorization to access.<BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'
."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach. We are sorry for any inconvenience caused and we will do all we
can to fix the error as soon as possible.<BR>
</FONT>'
;
break;


//Error 403 - Access Forbidden
case 403:
$errorname = 'Error 403 - Access Forbidden';
$errordesc = '<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">Access
Forbidden</FONT></B><FONT face="Verdana, Arial, Helvetica, sans-serif" size="2"><BR>
Error 403<BR>
<BR>
Access to the URL that you requested, is forbidden.<BR>
<BR>
If this problem persists please report it by sending an e-mail to <A href="mailto:'
."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach. We are sorry for any inconvenience caused and we will do all we
can to fix the error as soon as possible.<BR>
</FONT>'
;
break;


//Error 404 - Page Not Found
case 404:
$errorname = 'Error 404 - Page Not Found';
$errordesc = '<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">File Not
Found</FONT></B><FONT face="Verdana, Arial, Helvetica, sans-serif" size="2"><BR>Error 404<BR>
<BR>
We'
re sorry but the page you are looking for cannot be found.<BR>
<
BR>
If
this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach
. We are sorry for any inconvenience caused and we will do all we
can to fix the error
as soon as possible.<BR>
</
FONT>';
break;


//Error 500 - Server Configuration Error
case 500:
$errorname = '
Error 500 - Server Configuration Error';
$errordesc = '
<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">Server
Configuration Error
</FONT></B><FONT size="2" face="Verdana, Arial, Helvetica, sans-serif"><BR>
Error 500<BR>
<
BR>
The URL that you requested, resulted in a server configuration error.
It is possible that the condition causing the problem will be gone by
the time you finish reading this
. <BR>
<
BR>
If
this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach
. We are sorry for any inconvenience caused and we will do all we
can to fix the error
as soon as possible.<BR>
</
FONT>';
break;


//Unknown error
default:
$errorname = '
Unknown Error';
$errordesc = '
<B><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif">Unknown Error</FONT></B><FONT size="2" face="Verdana, Arial, Helvetica, sans-serif"><BR>
The URL that you requested, resulted in an unknown error.
It is possible that the condition causing the problem will be gone by
the time you finish reading this
. <BR>
<
BR>
If
this problem persists please report it by sending an e-mail to <A href="mailto:'."$email".'">'."$email".'</A>,
mentioning the error message received and the page you were trying to
reach
. We are sorry for any inconvenience caused and we will do all we
can to fix the error
as soon as possible.<BR>
</
FONT>';

}

//Display selected error message
echo($errordesc);

//E-mail error to your e-mail address (If you do not wish to receive emails delete the following paragraph)
$datetime = date("l dS of F Y H:i:s");
$message = "<i>The following error has been received on "."$datetime\n</i><br>\n<br>\n";
$message .= "<b><i>$errorname</i></b><br>\n";
$message .= "<i>Requested URL:</i> " . $requested_url . "\n<br><i>Referring URL:</i> " . $referring_url;
$to = "$email";
$subject = "Web Site Error";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$headers);
//End of E-mail sender

?>


Submitted by sabreweb on 29-07-2004 3:38


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net  Web Analytics