There are two parts to this script. The first part, functions.inc.php is used to e-mail the error code to a recipiant of your choice. The second part you must place on the error page itself, above all the HTML/CODE that is already their.
***********PART 1************
PHP Code:
<?php
/**
* @domain: DESILVA.BIZ
* @file: FUNCTIONS.INC.PHP
* @author: J de Silva
* @website: www.desilva.biz
* @email: scripts[AT]desilva[DOT]biz
* @copyright: Gen.I designs
* @date: August 19th, 2003
* @version: n/a
* @about : The 'engine' behind a simple PHP error page.
This script will send an e-mail to the address
specified including a subject with the error
code, and a breif message that includes the
error code, the date, the IP, and the page
that was not found.
*
/*===================================*/
function send_error_email( $error_code='Undefined' )
{
// set the TO: email address
// make sure to change [email]johndoe@domain.com[/email] to the
// address you wish the e-mail be sent to
$to = 'johndoe@domain.com';
// set the SUBJECT: e-mail
$subject = "An error has occured - type: $error_code";
// set the MESSAGE: e-mail
$message = "The following error has occured:\r\n"
."--------------------------------\r\n\r\n"
." Type: $error_code\r\n"
." Page: {$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}
\r\n"
." Time: ".date('d/m/Y H:i:s')."\r\n"
." From IP: {$_SERVER['REMOTE_ADDR']}\r\n\r\n"
."Regards,\r\n"
."Your hard-working web server.";
$headers = "From: webserver@{$_SERVER['SERVER_NAME']}\n"
."Reply-To: webserver@{$_SERVER['SERVER_NAME']}\n"
."X-Mailer: PHP/".phpversion();
// send the email
mail( $to, $subject, $message, $headers );
}
?>
***********PART 2************
PHP Code:
<?php
/**
* @domain: DESILVA.BIZ
* @file: 404.PHP
* @author: J de Silva
* @website: www.desilva.biz
* @email: scripts[AT]desilva[DOT]biz
* @copyright: Gen.I designs
* @date: August 19th, 2003
* @version: n/a
* @about : The script that sends the information to the
functions file which sends the e-mail. To
change the error code, just change the 404
from send_error_email( '404' ) to whatever
error you want. Place this file above the
404.php page, then display the rest of your
HTML below. Last thing you must enter is the
location of the functions.inc.php page. Just
as an example, we have said the page is
located at /errorpgs/functions.inc.php.
*
/*===================================*/
// FILENAME: 404.PHP
// include the filenamed : functions.inc.php...
// assuming that both files are in the same directory
include_once( $_SERVER['DOCUMENT_ROOT'].'/errorpgs/functions.inc.php' );
// Everytime someone reaches this page, i.e. 404.php, an email gets sent out
send_error_email( '404' );
?>
For help with this script, please use this thread:
http://desilva.biz/forum/viewtopic984.php