[1331781 views]

[]

[ads]

Odi's astoundingly incomplete notes

New entries | Code

RBL check in PHP

I am going to use blacklists for all the interactive parts on this website to get rid of comment spammers. If you would like to implement a similar thing, you can use the sample code blow:

function rbl_is_listed($ip, $rbl) {
  $comp = explode('.', $ip);
  if (sizeof($comp) != 4) die("Not a valid IPv4: $ip");
  $revip = join('.',array_reverse($comp));
  $result = gethostbyname("$revip.$rbl");
  return ($result == '127.0.0.2');
}

$ip = $_SERVER["REMOTE_ADDR"];
$rbl = 'bl.spamcop.net';
echo rbl_is_listed($ip,$rbl) ? 'listed' : 'not listed';

There are many DNS blacklists out there. Choose carefully.


posted on 2005-02-02 15:32 UTC in Code | 1 comments | permalink
Not all RBLs return 127.0.0.2
Some use the last number as a status to explain the RBL listing reason. Perhaps look for the first 3 numbers:
127.0.0.