Need help with refferer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yh0p2
Forum Newbie
Posts: 2
Joined: Sun Jan 25, 2004 12:13 am

Need help with refferer

Post 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]
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Have you outputted $HTTP_REFERER to see if it's blank?

You might need to use $_SERVER["HTTP_REFERER"].
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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");
}

?>
yh0p2
Forum Newbie
Posts: 2
Joined: Sun Jan 25, 2004 12:13 am

Post by yh0p2 »

wow! it worked perfectly. Thank you very much. :)
Post Reply