1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP script to only allow traffic from certain domain

Discussion in 'PHP & Perl' started by Website, Apr 25, 2011.

  1. Website

    Website Supreme Member

    Joined:
    Feb 8, 2008
    Messages:
    1,291
    Likes Received:
    286
    Location:
    whitehouse
    Is there a simple script to only allow traffic from a referring domain of my choice to a landing page of my choice and send all other visitors to another page of my choice?
     
  2. crazyflx

    crazyflx Elite Member

    Joined:
    Nov 9, 2009
    Messages:
    1,674
    Likes Received:
    4,825
    Location:
    http://CRAZYFLX.COM
    Home Page:
    There sure is, and it's very simple.

    Paste the following code into the header of your site:

    Code:
    <?
    $referrer = $_SERVER['HTTP_REFERER'];
        if (preg_match("/[COLOR=Red]domainnamehere[/COLOR]/",$referrer)) {
          header('Location: http://www.yourwebsite.com/special-page');
    
    } else {
          header('Location: http://www.yourwebsite.com/regular-page');
    };
    ?>
    Where it says "domainnamehere", leave off the "http://", "www." & ".com" So if the URL is http://www.somesite.com, put it in there as somesite

    I also suggest you give this post a read:
    http://www.blackhatworld.com/blackhat-seo/2720057-post10.html
     
    • Thanks Thanks x 1
    Last edited: Apr 25, 2011