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! Cheers! Dale
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:
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):
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.
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!