1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

open website only if refer is facebook

Discussion in 'PHP' started by david tsilosani, Feb 27, 2016.

  1. #1
    i want to allow users to see website only if refer is from facebook
    facebook page or timeline or like that...
    if refer is direct or from google i want to block him

    i have these code where is my mistake?

    <?php
    
    $allowed_domains = array('www.facebook.com/','https://www.facebook.com/');
    
    $REFERRER = $_SERVER['HTTP_REFERER'];
    
    if ($REFERRER == '') {
        // works
    }
    
    $domain = substr($REFERRER, strpos($REFERRER, '://')+3);
    $domain = substr($domain, 0, strpos($domain, '/'));
    
    if (!in_array($domain, $allowed_domains)) {
        exit(header('Location: error.php'));
    }
    
    ?>
    Code (markup):
     
    Last edited by a moderator: Feb 27, 2016
    david tsilosani, Feb 27, 2016 IP
  2. epikpoker

    epikpoker Well-Known Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #2
    Give this a try, I think the problem is the / you left on one of the domains:

    NOTE: I disabled the redirect for my testing.

    <?php
    
    $allowed_domains = array('www.facebook.com/','https://www.facebook.com/','www.facebook.com');
    
    //$REFERRER = $_SERVER['HTTP_REFERER'];
    
    $REFERRER = "https://www.facebook.com/";
    
    
    if ($REFERRER == '') {
      echo "No";
    }
    
    $domain = substr($REFERRER, strpos($REFERRER, '://')+3);
    
    $domain = substr($domain, 0, strpos($domain, '/'));
    
    if (!in_array($domain, $allowed_domains)) {
    
      echo "No";
    
      //exit(header('Location: error.php'));
    }
    else {
    
      echo "I am allowed";
    
    }
    
    ?>
    Code (markup):
     
    Last edited by a moderator: Feb 27, 2016
    epikpoker, Feb 27, 2016 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,740
    Likes Received:
    4,514
    Best Answers:
    123
    Trophy Points:
    665
    #3
    What about m.facebook.com?
     
    sarahk, Feb 27, 2016 IP
    KangBroke likes this.
  4. epikpoker

    epikpoker Well-Known Member

    Messages:
    213
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    #4
    Just have to add that to the list:

    $allowed_domains = array('www.facebook.com/','https://www.facebook.com/','www.facebook.com','m.facebook.com');
     
    epikpoker, Feb 28, 2016 IP