Site Navigation Code
  Home arrow Site Navigation Code arrow Dynamic Error Pages
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SITE NAVIGATION CODE

Dynamic Error Pages
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2004-06-24

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! Application Development Tools for the Mainframe Developer

    You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Download IBM Data Studio V1.1

    Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    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!


    NEW! Krugle, developerWorks, and code search

    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!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Section 508 of the U.S. Rehabilitation Act: Web accessibility compliance

    Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs).
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Tester for SOA Quality V7.0.1

    Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    SITE NAVIGATION CODE ARTICLES

    - Simple Menu System
    - Simply image viewer script
    - Simple File Lister
    - Dynamic Error Pages
    - BSoftEditor
    - Yahoo Status
    - Page numbers
    - PHP Search Navigator 1.0
    - Simple Page Navigation
    - An easy page browser ( prev 6 7 8 9 10 next )
    - AutoIndex PHP Script (Directory Indexer)
    - Bs_HtmlNavigation (Navigation and Sitemap cl...
    - Another Paging with Stage
    - Website Navigation via PHP
    - MySQL Paging Class





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT