I was wondering....
Every once in awhile I will upload a page just so people can see the script for it. However, the page contains links to images that do not exist, and when someone goes their, my 404 error handler comes back with a bunch of requests for lost images.
Is there a way to set aside a file and make it so any pictures and such will not be a 404 error and shall not generate an e-mail to me?
So I list the file
www.domain.com/test.html and the functions will see I do not want any e-mails concerning this specific page and therefore will not send an e-mail for any errors that page has.
This morning I had 368 e-mails on the same page because like 5 people viewed it. GRRRRRR
Here is what I have so far with the script:
Ex for the 404 page
Code:<?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' );
?>
Ex of the functions page
Code:<?php
// FILENAME: FUNCTIONS.INC.PHP
function is_reported()
{
// SET THE DOMAIN NAME BELOW (without the 'http://' or 'www' bits)
$domain = 'mydomain.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]';
$referred_by = ( isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown' );
// 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: http://www.{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}\r\n"
." Referring Page: $referred_by \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 );
}
}
?>
Any ideas?