Helpful Information
 
 
Category: General
Banning Specific Referers

OK, i've been trying to make a function like checkipban(); but that checks the referring site and if listed like IP's then it shows a vB Error message, heres what I got so far, It either bans every referrer or bans no referrer :ermm:

// ###################### Start checkreferrerban #######################
function checkreferrerban() {
// checks to see if the referring site is banned
global $enablebanning,$banreferrer,$webmasteremail,$session;

$banreferrer = trim($banreferrer);
if ($enablebanning==1 and $banreferrer!="") {
// get referring sites address
$referreraddress=getenv("$HTTP_REFERER");
// get all banned referrers from the db
$dbdomain=explode(" ", preg_replace("/[[:space:]]+/", " ", $banreferrer) );
// get domain for all banned referrers
while (list($key,$val)=each($dbdomain)) {
//get referring host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i", ".$referreraddress", $matches);
$host = $matches[2];
//get domain name from URL
preg_match("/[^\.\/]+\.[^\.\/]+$/",$host,$matches);
$match=$matches[0];
$hostdomain=explode(" ", $match);
//check against each banned referrer in the db
while (list($key,$val)=each($hostdomain)) {
if (strstr(" ".$match," ".trim($val))!="") {
eval("standarderror(\"".gettemplate("error_banref")."\");");
}
}
}
}
}

Its based on this fucnction:

// ###################### Start checkipban #######################
function checkipban() {
// checkes to see if the current ip address is banned
global $enablebanning,$banip,$webmasteremail,$session;

$banip = trim($banip);
if ($enablebanning==1 and $banip!="") {
$ipaddress=getenv("REMOTE_ADDR");

$addresses=explode(" ", preg_replace("/[[:space:]]+/", " ", $banip) );
while (list($key,$val)=each($addresses)) {
if (strstr(" ".$ipaddress," ".trim($val))!="") {
eval("standarderror(\"".gettemplate("error_banip")."\");");
}
}
}
}

Any help would be appriciated :D

You can ban referrers with .htaccess already. But you probably knew that, and want a PHP version for those without .htaccess.










privacy (GDPR)