Only allow traffic if coming from certain referral website?

Discussion in 'Programming' started by scriptmakingman, Aug 4, 2009.

  1. #1
    So, basically I'm looking for a basic script so that a website will only allow you "in" when you come from another referring website.

    For example, you have two websites. Website A and website B.

    You try and go straight to website B, but your denied because you didn't come from the correct referring website.

    Then, you go to website A then website B and then you can access website B because you came from website A.

    Does that make sense? I don't know how to script that myself...thought I would ask some of you geniuses! :D

    Cheers!
    Dale
     
    scriptmakingman, Aug 4, 2009 IP
  2. ricky92

    ricky92 Active Member

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    58
    #2
    It should be pretty easy...
    <?php
    session_start();
    if ($_SESSION['verified_referral'])
    {
        if (preg_match('#^http[s]?://www\.yourwebsitehere\.com#', $_SERVER['HTTP_REFERER']))
        {
            $_SESSION['verified_referral'] = true;
        }
        else
        {
            die('Error: wrong referral');
        }
    }
    ?>
    PHP:
     
    ricky92, Aug 4, 2009 IP
  3. scriptmakingman

    scriptmakingman Active Member

    Messages:
    280
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Alright, looks simple enough!
    Thanks!
     
    scriptmakingman, Aug 4, 2009 IP
  4. lambda1

    lambda1 Well-Known Member

    Messages:
    993
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    wow ricky, very good code :)..can we do it with JS too??
     
    lambda1, Aug 4, 2009 IP
  5. ricky92

    ricky92 Active Member

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Yes, even though it would be easier to bypass by just disabling js...
    <script type="text/javascript">
    if (!document.cookie.match(/referrercheck=1/))
    {
        if (document.referrer.match(/^http[s]?:\/\/www\.yoursitehere\.com/))
        {
            document.cookie = "referrercheck=1";
        }
        else
        {
            document.body.innerHTML = 'Wrong referrer';
        }
    }
    </script>
    Code (markup):
     
    ricky92, Aug 4, 2009 IP
  6. Zizzi

    Zizzi Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This method will work fine for simple protection. But referral headers can easily be spoofed! Don't bank on assumption that the traffic you are receiving is actually coming from the site you enter in your script.
     
    Zizzi, Aug 4, 2009 IP
  7. prince718

    prince718 Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hello. I am a non programmer, And I am looking for a similar script...

    What i need is a script, that Redirects ONLY if coming from a site of my choosing..

    So, if I am coming from SiteA.xom, and I click on a link to go to SiteB.xom, then it redirects to a url of my choosing.... I DONT want a person to enter Siteb.xom directly and be redirected..... HELP!
     
    prince718, Jun 12, 2010 IP