404 Error Referer Script Problems

This is a discussion on 404 Error Referer Script Problems within the PHP Language forums, part of the PHP Programming Forums category; Hello, I am having trouble extracting the original referer in my 404 error script. This is what I have so ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-18-2003
Alex
 
Posts: n/a
Default 404 Error Referer Script Problems

Hello,

I am having trouble extracting the original referer in my 404 error script.
This is what I have so far:

1) I set the .htaccess file to the following and it works fine:

ErrorDocument 404 /404.php

2) I've tried the following variables and they all produce the same results:

$REQUEST_URI
$HTTP_REFERER
$REDIRECT_URL

3) The above mentioned variables all return "/404.php" and not the
originally requested page.

I'm a little new at this and any assistance would be greatly appreciates!

Many Thanks,

Alex


Reply With Quote
  #2 (permalink)  
Old 09-18-2003
Andy Jeffries
 
Posts: n/a
Default Re: 404 Error Referer Script Problems

On Thu, 18 Sep 2003 09:12:53 +0000, Alex wrote:
> I am having trouble extracting the original referer in my 404 error script.
> This is what I have so far:
>
> 1) I set the .htaccess file to the following and it works fine:
>
> ErrorDocument 404 /404.php
>
> 2) I've tried the following variables and they all produce the same results:
>
> $REQUEST_URI
> $HTTP_REFERER
> $REDIRECT_URL
>
> 3) The above mentioned variables all return "/404.php" and not the
> originally requested page.
>
> I'm a little new at this and any assistance would be greatly appreciates!


$REQUEST_URI returns the correct thing for me.

Cheers,


Andy
Reply With Quote
  #3 (permalink)  
Old 09-18-2003
Martin Lucas-Smith
 
Posts: n/a
Default Re: 404 Error Referer Script Problems




> > I am having trouble extracting the original referer in my 404 error
> > script.


What you want is:



<?php
if (isSet ($_SERVER['HTTP_REFERER'])) {
# if (eregi (('http://' . $_SERVER['SERVER_NAME']), $_SERVER['HTTP_REFERER'])) {
echo "\n<p>A message to the webmaster has just been sent automatically, to inform her/him to make arrangements$

$recipient = 'webmaster@YOURDOMAIN';
$website_name = 'NAME OF WEBSITE';

$subject = "{$_SERVER['SERVER_NAME']} error: 404 (non-existent resource)";
$mailheaders = "From:$websiteName website monitor <$recipient>\n";
$message = "\nA 404 message was generated from someone loading a resource on {$_SERVER['SERVER_NAME']}\n\n";
$message .= " The resource is at {$_SERVER['HTTP_REFERER']}\n";
$message .= " which attempts to load http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}";
$browserDescription = (isSet ($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
$message .= "\n\n" . $_SERVER['REMOTE_ADDR'] . "\n" . $browserDescription;
mail ($recipient, $subject, wordwrap ($message), $mailheaders);
# }
}
?>




(Sorry if the lines wrap.)

Uncomment the two lines beginning with # if you want to enable broken link
detection for referrers ONLY within your site.

Bear in mind that you will get a few spurious results due to badly
configured spambots/scumbots and all sorts of other rubbish out there. If
you get a referrer of www.iaea.org I personally would ban that IP.




Martin Lucas-Smith www.geog.cam.ac.uk/~mvl22
www.lucas-smith.co.uk


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0