Web Hosting Talk







View Full Version : checking referral?


acctman
04-10-2009, 01:52 PM
How can I only allow a .php link to load if the referring page is a site on my server OR clicked link on the main site.

example: user copies php link and post on a forum (link should now load)

user clicks the site.com/image.php link on the site (link loads)
site.com/image.php is linked on to another site on-server-to.com/ link should load. Can i make it so Server IP: 1.1.1.1 can load the link but all outside hotlinks for the file will not load?

The Universes
04-10-2009, 01:55 PM
You can achieve this by having your php script check $_SERVER['HTTP_REFERER'] and make sure it contains your domain names or IPs.

acctman
04-10-2009, 02:59 PM
You can achieve this by having your php script check $_SERVER['HTTP_REFERER'] and make sure it contains your domain names or IPs.

do you have an example as to how you can list multiple site in a php code with $_SERVER['HTTP_REFERER']

acctman
04-10-2009, 03:17 PM
how does this look?


$referers = array(
'1.1.1.88',
'1.1.1.89',
'1.1.1.82',
);
if ($_GET['sec'] != 3 && $userid == '' || in_array(!eregi($referers, $_SERVER['HTTP_REFERER']))) {
header("Location: http://www.site.com");
exit;
}