Referrer Block

Discussion in 'PHP' started by Ang3r, Sep 11, 2008.

  1. #1
    Is it possible to block a refferer using PHP?
    Don't tell me to do it by .htaccess .. I wanna know if it's possible via PHP.
     
    Ang3r, Sep 11, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes. Use the var
    $_SERVER['HTTP_REFERER']
    to match against it
     
    JAY6390, Sep 11, 2008 IP
  3. Ang3r

    Ang3r Peon

    Messages:
    88
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Suppose I want to show a text to visitor that came from unblocked refferer or came without referrer and don't wanna show it to visitor came for blocked refferer.If I use following code..

    <?php
    $ref=@$HTTP_REFERER;
    $blank = "";
    $blockedref = "http://www.badhost.com/";
    if($ref != $blank && $ref != $blockedref)
    echo "Text to show to unblocked refferer";
    else
    die();
    ?>
    PHP:
    It will only blocked the specific URL I defined in $blockedref .. If a visitor come from http://www.badhost.com/dir/page.php .. It will not block that.
    How can I block the entire URL ..
     
    Ang3r, Sep 11, 2008 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    Use the dirname() function on the url string.
     
    Kaizoku, Sep 11, 2008 IP
  5. NoNameNoFortune

    NoNameNoFortune Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $blockedref = "badhost.com";
    $ref = @$_SERVER['HTTP_REFERER'];
    if( $ref && strpos( $ref, $blockedref ) !== false )
      die();
    PHP:
    =;-)
     
    NoNameNoFortune, Sep 12, 2008 IP