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! |
Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
|
|
|
|
Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. 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!
|
|
|
|
Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |