Google Answers Logo
View Question
Q: Custom PHP Script : Simple RBL Check for REMOTE_IP ( Answered,   0 Comments )
Subject: Custom PHP Script : Simple RBL Check for REMOTE_IP
Category: Computers > Programming
Asked by: captainnemo-ga
List Price: $200.00
Posted: 04 Jul 2004 01:21 PDT
Expires: 03 Aug 2004 01:21 PDT
Question ID: 369452

Im interested in having a very computer savvy individual, code a
somewhat simple (or perhaps not?) PHP script that will check the
incoming REMOTE_IP (I'm not fluent with PHP) IP address in the popular
RBL list and verify whether an entry for that IP exists. I would like
to be able to <? include ?> the provided script on top of every one of
my pages, and then limit access to my site if the remote IP of the
visitor is found in the RBL database.

Please ask any questions you may have. Thank you in advance.
Subject: Re: Custom PHP Script : Simple RBL Check for REMOTE_IP
Answered By: tox-ga on 04 Jul 2004 17:20 PDT

I have completed your requested script. You can download the file at:

There are two versions of the script, one for a unix server and one
for a windows server. The reason for this is that the windows port of
php does not have one of the required functions. If you are unsure of
which your webserver is running, use the unix version
(dnsblquery_unix.php) first. If you recieve an error ("Fatal error:
Call to undefined function: checkdnsrr()"), then switch to the windows
version (dnsblquery_win.php).

To use the script, simply insert the line:
<? include("dnsblquery_unix.php"); ?>
<? include("dnsblquery_win.php"); ?>
at the top of your scripts, modifying the include path according to
your directory structure.

The script currently uses the database (which is
the sbl and xbl database combined). This can be easily changed if you
have another preference. I have also designed the script so that you
can check multiple block lists. To do so, simply modify the $dnsbllist
array (the line that currently looks like "$dnsbllist =
array("");") in the dnsblquery function. Remember
to keep the following format:
$dnsbllist = array("", "blocklist2", "blocklist3");

You can also change the behaviour of the script for when an IP is
found on the block list. Currently, it displays the line:
"Your IP,, has been blacklisted by"
Possible other behaviours would be a redirection (replace the echo
line with "header('location: new_page_name.html');"), nothing (remove
the echo line), or a script of your own.

A working example of the script can be found at:
A known blacklisted IP is (for your testing purposes).

If you have any questions, please do not hesitate to ask for
clarification. I am willing to work until you are completely satisfied
with the answer.

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy