PDA

View Full Version : Help with ip block


Nightfire
08-14-2002, 09:36 AM
$banned_ips = array("BANNED_IP", "another baned ip");


function is_ip_banned($REMOTE_ADDR,$banned_ips) {
if(is_array($banned_ips))
{
$banned_ips = str_replace("*", "[0-9]{1,3}", $banned_ips);
while (list($key,$value) = each($banned_ips))
{
if(ereg($banned_ips[$key], $REMOTE_ADDR))
{
die("You have been banned. If you believe this has been done in
error, contact the webmaster.");
}
}
}
}


I have a huge file of ip's to block for a clients site, is there an easier way to block the ip's than listing each one in the array? Can I include a file there?

Spookster
08-14-2002, 02:03 PM
Are you storing them in a text file? Don't have access to database?

Nightfire
08-14-2002, 04:53 PM
The site I'm working on doesn't have a database, only flat files I'm afriad :(

Nightfire
08-17-2002, 02:03 AM
Any ideas?

Spookster
08-17-2002, 02:15 AM
Instead of reading all the IP's from the file into an array then searching why not just search the file for the matching IP.