404 Error Referer Script Problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    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


  • Andy Jeffries

    #2
    Re: 404 Error Referer Script Problems

    On Thu, 18 Sep 2003 09:12:53 +0000, Alex wrote:[color=blue]
    > 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![/color]

    $REQUEST_URI returns the correct thing for me.

    Cheers,


    Andy

    Comment

    • Martin Lucas-Smith

      #3
      Re: 404 Error Referer Script Problems



      [color=blue][color=green]
      > > I am having trouble extracting the original referer in my 404 error
      > > script.[/color][/color]

      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@YOUR DOMAIN';
      $website_name = 'NAME OF WEBSITE';

      $subject = "{$_SERVER['SERVER_NAME']} error: 404 (non-existent resource)";
      $mailheaders = "From:$websiteN ame 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']}";
      $browserDescrip tion = (isSet ($_SERVER['HTTP_USER_AGEN T']) ? $_SERVER['HTTP_USER_AGEN T'] : '');
      $message .= "\n\n" . $_SERVER['REMOTE_ADDR'] . "\n" . $browserDescrip tion;
      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



      Comment

      Working...