sgrayban Posted April 9, 2010 Share Posted April 9, 2010 (edited) Now this is a FREE dynamic error page script. Not coded so you can edit it how every you want it. This script was originally released in 2004 as GPL/FREE code. I used this same code back in 2005-2006 for a website I developed. Except I rarely used the built-in email feature in this script. Read the comments in the script to enable the email feature or add new error codes and/or localization. Enjoy !!! <?php /* Dynamic Error Pages v1.02 Copyright (c) 2004 Sabre Web Design <http://www.sabrewebdesign.com/> All rights reserved. ** Last Modified Friday 09 April 2010 ** Source originally found at: ** http://www.codewalkers.com/c/a/Site-Navigation-Code/Dynamic-Error-Pages/ ** ** I modified it and commited out the email part if a error page was found ** however if you want that function simply remove the // in front of it. ** Scott Grayban <https://www.borgnet.net> 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 a file called errorpages.php * (Optional) 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 /PATH-TO-YOUR-WHMCS-ROOT/errorpage.php?error=400 ErrorDocument 401 /PATH-TO-YOUR-WHMCS-ROOT/errorpage.php?error=401 ErrorDocument 403 /PATH-TO-YOUR-WHMCS-ROOT/errorpage.php?error=403 ErrorDocument 404 /PATH-TO-YOUR-WHMCS-ROOT/errorpage.php?error=404 ErrorDocument 500 /PATH-TO-YOUR-WHMCS-ROOT/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) /* remove this line if you want this feature $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); remove this line if you want this feature */ //End of E-mail sender ?> Edited April 9, 2010 by sgrayban typo 0 Quote Link to comment Share on other sites More sharing options...
sgrayban Posted April 9, 2010 Author Share Posted April 9, 2010 BTW if you break it not my fault. Error pages are nearly 99% idiot proof. Don't come here posting it doesn't work when I know it does if you follow the instructions to use it. 0 Quote Link to comment Share on other sites More sharing options...
FlexiHost Posted August 7, 2010 Share Posted August 7, 2010 Thanks heaps for supplying that page, works very well. 0 Quote Link to comment Share on other sites More sharing options...
sgrayban Posted August 7, 2010 Author Share Posted August 7, 2010 Your welcome 0 Quote Link to comment Share on other sites More sharing options...
uberhost Posted December 26, 2010 Share Posted December 26, 2010 Sorry to dig up an older topic but I just had to say "job well done" to Scott Grayban. This mod is FREE and very useful - much better than maintaining separate custom error pages. I've installed ours in our webroot so that it covers our regular website as well as the WHMCS folder. Works a treat. Thank you! Rick 0 Quote Link to comment Share on other sites More sharing options...
sgrayban Posted December 27, 2010 Author Share Posted December 27, 2010 thanks - its not a hard addon to use 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.