how to allow only certain referrals website

Discussion in 'General Scripting Chat' started by ninatsa, Jul 10, 2015.

  1. ninatsa

    ninatsa Regular Member

    Joined:
    Nov 13, 2011
    Messages:
    306
    Likes Received:
    6
    Hello there,
    I want to allow referrals only from one domain and limit access to direct visitors and from other domains, how to make it?
     
  2. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,234
    Occupation:
    Retired
    Location:
    Old Peoples Home
    In PHP I would put all the allowed domains in an array and when someone hits your website, check their referrer against the array. If there is a match let them through else bounce elsewhere.

    Give more details and you will get a better answer - are you using plain HTML sites, PHP, Wordpress............?
     
  3. ninatsa

    ninatsa Regular Member

    Joined:
    Nov 13, 2011
    Messages:
    306
    Likes Received:
    6
    thank you very much for the reply, it's a wordpress site and want to allow only fb traffic on it, want to block direct traffic and traffic from other domains.
     
  4. quietlearner

    quietlearner Junior Member

    Joined:
    Jun 22, 2015
    Messages:
    116
    Likes Received:
    42
    Add this to the top of your wp-config.php file after <?php:

    PHP:
    if (stripos($_SERVER['HTTP_REFERER'], 'facebook') === false) {
      
    header('HTTP/1.0 403 Forbidden');
      exit;
    }
    Note that this will block crawlers including Googlebot from accessing your page.
     
    Last edited: Jul 10, 2015
  5. ninatsa

    ninatsa Regular Member

    Joined:
    Nov 13, 2011
    Messages:
    306
    Likes Received:
    6
    thanks but it doesn't work :(
    isn't there any plugin to fulfill this function?
     
  6. quietlearner

    quietlearner Junior Member

    Joined:
    Jun 22, 2015
    Messages:
    116
    Likes Received:
    42
    Whoops sorry about that, I wrote it quickly. I mixed up the two parameters for stripos(). This works and has been tested:

    PHP:
    if (stripos($_SERVER['HTTP_REFERER'], 'facebook') === false) {
      
    header('HTTP/1.0 403 Forbidden');
      exit;
    }
     
    • Thanks Thanks x 1
  7. ninatsa

    ninatsa Regular Member

    Joined:
    Nov 13, 2011
    Messages:
    306
    Likes Received:
    6
    aww thank you very very much, you've made my day :star:i tested many codes but nothing worked, thanks man :arms:
    but can it function only for home page? 'cause i can't access admin and other pages
     
    Last edited: Jul 10, 2015
  8. quietlearner

    quietlearner Junior Member

    Joined:
    Jun 22, 2015
    Messages:
    116
    Likes Received:
    42
    PHP:
    if (in_array($_SERVER['REQUEST_URI'], array('/''/index.php')) && stripos($_SERVER['HTTP_REFERER'], 'facebook') === false) {
      
    header('HTTP/1.0 403 Forbidden');
      exit;
    }
    Try this. You can add as many different pages as you want inside the array('/', '/index.php') array.
     
    • Thanks Thanks x 1
  9. ninatsa

    ninatsa Regular Member

    Joined:
    Nov 13, 2011
    Messages:
    306
    Likes Received:
    6

    it works, you were a great help for me, thank you :*