Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created September 11, 2014 15:28
Show Gist options
  • Save khoand0000/f3308829064c81996af5 to your computer and use it in GitHub Desktop.
Save khoand0000/f3308829064c81996af5 to your computer and use it in GitHub Desktop.
http://phpsnips.com/544/Blacklist-Lookup#.VBG-zfmSySo This blacklist lookup function is a modification of this snippet. The difference is, that it returns if it suspects an ip is a spammer. If 50% or more of the lookups think your a spammer, the function returns true otherwise false.
<?php
function blacklist($ip){
$listed = true;
$dnsbl_lookup = array(
"dnsbl-1.uceprotect.net",
"dnsbl-2.uceprotect.net",
"dnsbl-3.uceprotect.net",
"dnsbl.dronebl.org",
"dnsbl.sorbs.net",
"zen.spamhaus.org"
); // Add your preferred list of DNSBL's
$lookups = count($dnsbl_lookup);
$total = 0;
if($ip){
$reverse_ip = implode(".", array_reverse(explode(".", $ip)));
foreach($dnsbl_lookup as $host){
if(checkdnsrr($reverse_ip.".".$host.".", "A")){
$total++;
}
}
}
$percent = ($total / $lookups) * 100;
if($percent >= 50){
return true;
}else{
return false;
}
}
if(blacklist($_SERVER["REMOTE_ADDR"])){
die("Your on the blacklist!");
}
// Continue with page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment