1
   

Additions to the Error Page Script

 
 
Reply Mon 15 Sep, 2003 06:30 pm
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?
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 1,157 • Replies: 7
No top replies

 
Craven de Kere
 
  1  
Reply Mon 15 Sep, 2003 09:47 pm
Hmm, very very tough question.

Thing is, each missing image will return a 404 and your htaccess file is telling all 404s to go to this page.

IMO, it'd be easier to solve this one through htaccess.

I am VERY busy these days so I will not be able to help.

But I can give you a solution that will work instantly.

Use different htaccess files for the image directory and don't forward the image 404s to that script.

There is a downside, you will keep getting them if you link to targets outside of the folder you specified. But that is easier to take care of (use PHP to dynamically write URLs) than what you are requesting.
0 Replies
 
BobbyDouglas
 
  1  
Reply Mon 15 Sep, 2003 09:55 pm
Ah busy man! I will keep an eye out for a way to get this to work.

I want ALL image 404s to be sent to me, except for the list of websites that I want to exclude.

(So Craven is stumped? Razz)
0 Replies
 
Craven de Kere
 
  1  
Reply Mon 15 Sep, 2003 10:01 pm
I'm not stumped, I just know that it would take me a while to make a code based solution when an easier planning based solution is easier.

Each folder you use can have their own 404 pages. The secret is simply to use htaccess files to specify only folders with no missing files for that script. Direct the other folder's 404 errors to a different page with manual reporting (I used to use a script with one click reporting).

So in short, the solution is possible on a code level but there are much easier solutions that make it something I personally wouldn't spend time coding for.

It simply makes more sense to do this through htaccess files and differentiate directories.

Now your last comment makes it a bit more reasonable. If you want an exclusion list you can always do it through a simple array. But IMO the htaccess solution is much better.
0 Replies
 
BobbyDouglas
 
  1  
Reply Thu 25 Sep, 2003 01:00 pm
Ok, what about this idea?

Limit the amount of e-mails to 1 e-mail per a specific # of errors that is user defined.

So lets say I have 100 different 404s on my site, and I want 1 e-mail for every 20 times an error occurs.

Would you do something like this: Every time the error happens, record it to a specific file, then check the file for the # of errors. If the # of errors is => a specific number that I could change whenever I want, it will send an e-mail will ALL the errors in the one e-mail.
0 Replies
 
BobbyDouglas
 
  1  
Reply Thu 25 Sep, 2003 01:00 pm
Also, can these types of scripts works in some cgi-bin folders? Someone said it didn't work for him, I am just wondering if it would work for some hosts, all hosts, or no hosts?
0 Replies
 
Craven de Kere
 
  1  
Reply Thu 25 Sep, 2003 02:41 pm
I'd definitely not do the logging. Let me explain why.

When you have a small site and do all the pages manually this is useful. You have a bunch of pages and you might misplace them.

But once your traffic increases you definitely do not want the emailing.

When I get 404s it's ONLY because I remove images and redesign and when somone pulls my old page off Google's cache all the images give a 404.

Your stats tracking system should already be logging the 404s and the referral that they came from. You should not be making URLs that have to be changed (other than just images etc) so the 404s should really only be known issues for you.

Ok, so if I'd use this script I'd only place it in specific directories I want to track. I'd use htaccess files to prevent image 404s from sending emails.

The logging would be a waste, the server automatically logs all of thif for you, you are better off just learning to analyze web logs.

And no this script won't work for all hosts. It's PHP so any host without it won't be able to use it and the method used to determine the 404 page is a Linux thing.
0 Replies
 
BobbyDouglas
 
  1  
Reply Fri 26 Sep, 2003 07:12 pm
Ok, Understabdable. However, someone said the script did not work in their cgi-bin directoy. Any ideas on why that would be? It works in another directory though. Is this usual?
0 Replies
 
 

Related Topics

Webdevelopment and hosting - Question by harisit2005
Showing an Ico File - Discussion by Brandon9000
how to earn money in internet - Discussion by rizwanaraj
The version 10 bug. Worse then Y2K! - Discussion by Nick Ashley
CSS Border style colors - Question by meesa
There is no Wisdom in Crowds - Discussion by ebrown p
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
I'm the developer - Discussion by Nick Ashley
 
  1. Forums
  2. » Additions to the Error Page Script
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 05/07/2024 at 02:18:49