Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Spamhaus DBL example
/* 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.

Copy link

@ozh ozh commented Nov 21, 2012

Does. Not. Work.
You're just checking DNS records. Nowhere in this code there is any Spamhaus action.


This comment has been minimized.

Copy link

@bradleybensmith bradleybensmith commented Apr 12, 2014

As-is, it does not work. However, after doing some research, I figured out that the $domain variable should be set like $ where $revip is the reverse IP address of what you're checking.

For example:

$ip = "";
$revip = implode(".", array_reverse(explode(".", $ip, 4), false)); //
$dns = dns_get_record($revip . "");

The rest is basically true, but it's better to check the actual results:

if ($dns != null && count($dns) > 0) {
    foreach ($dns as $entry) {
        if (in_array($entry['ip'], array('', '', '')))
            return true;

The return codes are listed here:


This comment has been minimized.

Copy link

@shawnkhall shawnkhall commented Oct 26, 2015

$domain = $parsed_url['host'] . '';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment