Forum Moderators: coopster

Message Too Old, No Replies

Php Arrays

         

Rob83

2:10 am on Apr 8, 2005 (gmt 0)



Hiya,

Great Forum! I got a hold of this script that checks an IP against blacklisted databases. However, it only displays 1 listing, even if there are multiple. How could I get it to display all of them?


<?php

// Retrieves the IP of the client
function getip () {
$ip="192.168.1.0";
return $ip;
}

// Queries multiple block lists
function dnsblquery ($ip) {
$dnsbllist = array(
"spamlist1.example.net",
"spamlist2.example.net",
"spamlist3.example.net",
"spamlist4.example.net",
"spamlist5.example.net" // Keep this one last.
);

if ($ip) {
// Reverses the IP
$ips = explode(".", $ip);
$ipreverse = "$ips[3].$ips[2].$ips[1].$ips[0]";
// Queries the block lists listed in dnsbllist
for ($i=0;$i<count($dnsbllist);$i++) {
if (checkdnsrr("$ipreverse.$dnsbllist[$i]", "A")) {
// Returns the blacklist the queried IP is on
return $dnsbllist[$i];
}
}
}
return FALSE;
}

$blocker = dnsblquery(getip());
if ($blocker) {
// Blocked behaviour
// -----------------

echo "Your IP, ".getip().", has been blacklisted by $blocker";

// -----------------
exit;
}

[edited by: coopster at 10:42 am (utc) on April 8, 2005]
[edit reason] generalized url per TOS [webmasterworld.com] [/edit]

IamStang

3:28 pm on Apr 9, 2005 (gmt 0)

10+ Year Member



This response is not going to help you find a solution. I am just curious as to why one would want to have a "blacklist by IP addy" list/script?

The majority of web users do not have static ip addresses. So, wouldn't you be running the risk of banning someone that has never been to your site?

I guess what I am getting at is, if I were to get blacklisted on your site, could I not simply open a command prompt, ipconfig/release ipconfig/renew? I have a new ip addy so, I'm in. Right? And the next poor sap that gets my "banned" ip cant get in.

Like I said, just curious. Trying to learn like everyone else.

IamStang

coopster

7:07 pm on Apr 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Rob83.

In order to return all of them you would need to accumulate the values instead of returning the first one you hit. This part of your code

// Returns the blacklist the queried IP is on 
return $dnsbllist[$i];

is instructing the loop to quit and return the first one hit. You could initialize a variable to be an empty array and add to it upon each iteration/check against the list then upon completion of the loop return the array instead of the single value as you are today.