Spamhaus DBL example
<?php | |
/* Let's say the variable $input contains a user-submitted link */ | |
$parsed_url = parse_url($input); | |
if ($parsed_url != false) { | |
/* The domain should be found using the 'host' key */ | |
$domain = $parsed_url['host']; | |
/* Now check that domain against the DBL */ | |
$dbl_record = dns_get_record($domain); | |
/* If the resulting array is empty, the domain is clear for liftoff */ | |
if ($dbl_record != NULL && count($dbl_record) == 0) { | |
/* Do stuff with the good domain */ | |
} else { | |
/* Warn about a blocked domain */ | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
As-is, it does not work. However, after doing some research, I figured out that the For example: <?php
$ip = "50.31.209.254";
$revip = implode(".", array_reverse(explode(".", $ip, 4), false)); // 254.209.31.50
$dns = dns_get_record($revip . ".zen.spamhaus.org");
?> The rest is basically true, but it's better to check the actual results: <?php
if ($dns != null && count($dns) > 0) {
foreach ($dns as $entry) {
if (in_array($entry['ip'], array('127.0.0.2', '127.0.0.3', '127.0.0.4')))
return true;
}
}
?> The return codes are listed here: http://www.spamhaus.org/faq/section/DNSBL%2520Usage#202 |
This comment has been minimized.
This comment has been minimized.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Does. Not. Work.
You're just checking DNS records. Nowhere in this code there is any Spamhaus action.