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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
> > 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 |