Page 1 of 1

Need help with refferer

Posted: Sun Jan 25, 2004 12:13 am
by yh0p2
Hi, I've been trying to make anti-leech script.

Code: Select all

<?

if ($download == 1)
$allow = array("http://MYDOMAIN/","http://MYDOMAIN/"); 
$reffer = $HTTP_REFERER;
if($reffer) {
$yes = 0;
while(list($domain, $subarray) = each($allow)) {
if (ereg("$reffer",$subarray)) {
$yes = 1;
}
}
if ( $yes == 1) {
header("Location: http://MYDOMAIN/THEFILE.ZIP");
} else {
header("Location: http://MYDOMAIN/ERROR.PHP");
}
} else {
header("Location: http://MYDOMAIN/ERROR.PHP");
}

?>
everytime i do MYDOMAIN.COM/NOLEECH.PHP?download=1, it goes to error page no matter what.
I don't seem to find the problem...
?>[/php_man]

Posted: Sun Jan 25, 2004 12:22 am
by microthick
Have you outputted $HTTP_REFERER to see if it's blank?

You might need to use $_SERVER["HTTP_REFERER"].

Posted: Sun Jan 25, 2004 12:26 am
by Gen-ik
I think HTTP_REFERER also includes any variables that are in the URL.

Try something like this...

Code: Select all

<?php

$allowed = false;

$allow[] = "domainOne.com"; // ie http://www.domainOne.com
$allow[] = "domainTwo.net"; // ie https://domainTwo.net?name=bob

foreach($allow as $domainName)
{
    if(stristr($_SERVER["HTTP_REFERER"], $domainName) !== false)
    {
        $allowed = true;
    }
}

if($allowed)
{
    header("Location:somewhere.php");
}
else
{
    header("Location:somewhereElse.php");
}

?>

Posted: Sun Jan 25, 2004 12:31 am
by yh0p2
wow! it worked perfectly. Thank you very much. :)