/    Sign up×
Community /Pin to ProfileBookmark

broken link reporter

I work for a company which insists on using A LOT of static pages throughout their site. One of the problems we often see due to this is 404 errors, literally hundreds of them of a day. Tracking all of these is quite a pain, mostly because some of them are a pain.. and others are just curious or ignorant users playing with link structures.

I was assigned the task of figuring out how to make our own 404 errors be self reporting to the web design department. We have a few different domains and sub-domains, so that added a touch of complication to the process.

I came up with the following script that I in turn placed in the headers of our custom 404 page.

[code=php]
$refererChecks = array(“bar.com”,”foo.bar.com”,”myfoo.bar.com”);

$referer = $_SERVER[‘HTTP_REFERER’];

$refererDomain = $referer;
$refererDomain = str_replace(“http://”,””,$refererDomain);
$refererDomain = explode(“/”,$refererDomain);

$myURI = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

foreach($refererChecks as $thisDomain){
if($thisDomain == $refererDomain[0]){
$to = “[email protected]”;
$from = “[email protected]”;
$title = “Self Reporting Broken Link”;
$bodyText = “++++++++++++++ SELF REPORTING BROKEN LINK ++++++++++++++++nnnn
Link That Is Broken:
“.$myURI.”nn
Linked From:
“.$referer.”nnn
—- REPLYING TO THIS E-MAIL WILL SEND A RESPONSE TO ALL PARTIES ON THE MAILING LIST —-nn”;

@mail($to,$title,$bodyText,”From: $fromn”);

}
}
[/code]

Since the server fires off the 404 error for everything, be it images, or a physical page, or even an improperly typed url with a / after the filename, its a very thorough system.

BUT now we have a weird re-occurring bug. If a directory does not have an index.php/html/shtml/etc. file to produce for a index listing we give a 403 Forbidden and show the 404 page via Apache.

Now if users are requesting a page from a directory without (whatever/thisthing.php) it will for some reason on occasion fire off a 404 email to the web design dept. even though not only are there no links to the directory but also, there are not even any references to it.

I’m stumped and can’t figure out what the heck is going on.

Any input is appreciated

Thanks;
Chad

P.S. I also have a feeling it could be something to do with the way apache is handling the files, but I figured I would try in the PHP section first because I think I could possibly by pass or kill whatever apache is doing.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@LeeUNov 20.2006 — Check [URL=http://www.sabrewebdesign.com/support/scripts/errorpages.php]this link[/URL]. I'm pretty sure that's what you're looking for. I use it (I customized it a bit) and it works just fine. And, it's free! It will display a message to your visitor and send a notice of the error to you.
Copy linkTweet thisAlerts:
@chadillacauthorNov 20.2006 — thanks for the heads up, I'll probably stick to mine because we don't need to inform the user and such... but I will def. look at the source for insight ?.
Copy linkTweet thisAlerts:
@LeeUNov 20.2006 — No problem. Just to clear up though, it only informs the user that there has been an error. You can make it look like one of your own pages and customize the message. It only sends the e-mail to you.
Copy linkTweet thisAlerts:
@chadillacauthorNov 20.2006 — yea I know, I already have the frameworks laid out in mine to do the same, I'm just saying that we don't need any of that stuff plus we have to test against multiple domains, so it would probably be as much effort to tweak as it would to get mine trimmed to prevent that apache error. It appears to essentially be the same exact script just using different methods and they use some server properties I didn't know of at the time... like 'REDIRECT_STATUS'.
×

Success!

Help @chadillac spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...