Dynamic Error Pages

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
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 /errorpage.php
ErrorDocument 401 /errorpage.php
ErrorDocument 403 /errorpage.php
ErrorDocument 404 /errorpage.php
ErrorDocument 500 /errorpage.php
* And it's as simple as that!



Code:
<?php

*/
Created by o0slowpaul0o.
*/

// Setup
$email = 'error@example.com';  //Change to your email address

// Get Variables
$error = $_SERVER['REDIRECT_STATUS'];
$referring_url = $_SERVER['HTTP_REFERER'];
$requested_url = $_SERVER['REQUEST_URI'];
$referring_ip = $_SERVER['REMOTE_ADDR'];
$server_name = $_SERVER['SERVER_NAME'];

// Different error messages to display
switch ($error) {

# Error 400 - Bad Request
case 400:
$errorname = 'Error 400 - Bad Request';
$errordesc = '<h1>Bad Request</h1>
        <p>Error 400</p>
        <p>
        The URL that you requested, was a bad request.</p>
        <p>
        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.</p>';
   break;


# Error 401 - Authorization Required
case 401:
$errorname = 'Error 401 - Authorization Required';
$errordesc = '<h2>Authorization Required</h2>
        <p>Error 401</p>
        <p>
        The URL that you requested, requires pre-authorization to access.</p>
        <p>
        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.</p>';
   break;


# Error 403 - Access Forbidden
case 403:
$errorname = 'Error 403 - Access Forbidden';
$errordesc = '<h2>Access Forbidden</h2>
        <p>Error 403</p>
        <p>
        Access to the URL that you requested, is forbidden.</p>
        <p>
        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.</p>';
   break;


# Error 404 - Page Not Found
case 404:
$errorname = 'Error 404 - Page Not Found';
$errordesc = '<h2>File Not Found</h2>
        <p>Error 404</p>
        <p>
        We are sorry but the page you are looking for cannot be found.</p>
        <p>
        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.</p>';
   break;


# Error 500 - Server Configuration Error
case 500:
$errorname = 'Error 500 - Server Configuration Error';
$errordesc = '<h2>Server
        Configuration Error</h2>
        <p>Error 500</p>
        <p>
        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. </p>
        <p>
        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.</p>';
   break;


# Unknown error
default:
$errorname = 'Unknown Error';
$errordesc = '<h2>Unknown Error</h2>
        <p>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. </p>
        <p>
        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.</p>';

}

// Display selected error message
echo($errordesc);
if (!$referring_url == '') {
echo '<p><a href="'.$referring_url.'"><< Go back to previous page.</a></p>';
} else {
echo '<p><a href="javascript:history.go(-1)"><< Go back to previous page.</a></p>';

echo '<p align="right"><font size="1">Dynamic Error Pages from <a href="http://www.x10hosting.com/" title="x10hosting">Created By o0slowpaul0o</a>.</font></p>';

// E-mail section. Delete if you do not want to be sent e-mail notifications of errors.
$datetime = date("l dS of F Y - H:i:s");
$message .= '<i>The following error has been received on '.$datetime.'</i>';
$message .= '<br><br><b><i>'.$errorname.'</i></b>';
$message .= '<br><i>Requested URL:</i> <a href="http://'.$server_name.$requested_url.'">'.$requested_url.'</a>';
$message .= '<br><i>Referring URL:</i> <a href="'.$referring_url.'">'.$referring_url.'</a>';
$message .= '<br><br><i>IP Address:</i> '.$referring_ip;
$to = "$email";
$subject = "$errorname";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to,$subject,$message,$headers);
}
// End of e-mail section.
?>
 

Articz

New Member
Messages
864
Reaction score
0
Points
0
are we allowed to do this on x10 hosted sites as all error pages will be pages created by x10 not us
 

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
It shouldn't effect any other error pages the admins make for you. It just applys for your site.
 

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
I thought x10 was taking over the error pages as part of the new plan/ad reorganization.....
 

n4tec

Active Member
Messages
3,312
Reaction score
0
Points
36
The_Magistrate said:
I thought x10 was taking over the error pages as part of the new plan/ad reorganization.....

Certainly remember reading that too...
 

XUnreal

New Member
Messages
370
Reaction score
0
Points
0
In the .htaccess, could you do this:
ErrorDocument 404 /errorpage.php?error=404

Or would it result as an invalid sythax?
 

n4tec

Active Member
Messages
3,312
Reaction score
0
Points
36
Auvee said:
I don't think this is going to work once the new errordocument system is put in place.

-Auvee B.

have you seen my 404 error page? And when will the new error document system start?
 

Articz

New Member
Messages
864
Reaction score
0
Points
0
hey i was right for once woot thx for the tut tho mate will add to my collection of php script to use :)
 

o0slowpaul0o

New Member
Messages
254
Reaction score
0
Points
0
Not sure. Might be resort to an invalid Sythnax. You could try it.

I haven't had time to test it..Life is hell for me...Anyway, if it give you any invalidation, I'll try and make it work for you.

EDIT: Admins or mods can you delete this post please? Didn't see the second page of the topic.
 

dsfreak

New Member
Messages
1,338
Reaction score
0
Points
0
It is a nice tutorial. But, since x10 is taking over our error pages, it probably isnt going to work, but yea, good tutorial.
 
Top