Blocking "Blocked Referrer' -- how to

Discussion in 'Apache' started by AbdullahFarouk, Sep 16, 2006.

  1. #1
    Is there anyway to block Blocked Referrers from your site with htaccess?
     
    AbdullahFarouk, Sep 16, 2006 IP
  2. Slackware

    Slackware Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can do it with php easily
     
    Slackware, Sep 26, 2006 IP
  3. AbdullahFarouk

    AbdullahFarouk Peon

    Messages:
    96
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Could you point me in the right direction on how to do this?
     
    AbdullahFarouk, Sep 28, 2006 IP
  4. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use a regular expression to validate the Referer header.

    preg_match(
      '/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\//i',
      $_SERVER['HTTP_REFERER'],
      $captures
    );
    if (count($captures[0]) == 0) {
      exit('Sorry, you cannot access this page.');
    }
    
    PHP:
    Note that you may also be blocking legitimate visitors, as user agents are not required to send the referrer header.

    - P
     
    penagate, Sep 30, 2006 IP