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.)
By : sabreweb
<?php
/*
Dynamic Error Pages v1.02
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;
$message .= "\n<br><br><i>IP Address:</i> ".$_SERVER['REMOTE_ADDR'];
$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
?></form>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Site Navigation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |