Whenever a visitor visits the 404.php page, the script will send data to the functions.inc.php file saying this is error 404. Then it will check if the user has a cookie for that page, if not, then a cookie will be set, and then an e-maill will be sent to the specified address.
If the person already has a cookie for that specific page, then no e-mail will be sent. However, I keep getting an e-mail everytime someone visits the page. So there is something wrong with the cookie part.
Any ideas?
Code:<?php
// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// Begin PHP Code
// 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' );
// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// End PHP Code //
?>
***************And the functions.inc.php file:************
Code:<?php
// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// Begin PHP Code
// FILENAME: FUNCTIONS.INC.PHP
function is_reported()
{
// SET THE DOMAIN NAME BELOW (without the 'http://' or 'www' bits)
$domain = 'mrbobdouglas.com';
// ---------------------------------------------------------------
if( isset($_COOKIE['http_errors']) )
{
$_COOKIE['http_errors'] = unserialize( $_COOKIE['http_errors'] );
if( in_array($_SERVER['REQUEST_URI'], $_COOKIE['http_errors']) )
{
// this error page / url has been reported by this person before
return TRUE;
}
}
// this person has either NEVER reported an error before
// or this is a NEW url error to report
$_COOKIE['http_errors'][] = $_SERVER['REQUEST_URI'];
$value = serialize( $_COOKIE['http_errors'] );
setcookie( 'http_errors', $value, time() + 24*60*60, '/', './'.$domain, 0 );
unset( $domain, $value );
return FALSE;
}
function send_error_email( $error_code='Undefined' )
{
if( !is_reported() )
{
// set the TO: email address
$to = '[email protected]';
// 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 );
}
}
// Generator v2.0 Coded by: WWW.MRBOBDOUGLAS.COM, Script by JdS
// End PHP Code
?>
Thanks