blocked IP address

I have several web sites hosted on a shared server. They all have forms to fill out and all have IP address trapping. I get a lot of auto form fillers so added the following code

// Banned IP addresses

if (file_exists(“blockedIPs.txt”))
{
$ip = $_SERVER[‘REMOTE_ADDR’];
$fp = fopen("…/blockedIPs.txt",“r”);
$banned = fread($fp, 1024*1024);
fclose($fp);
$ips = explode("\n", $banned);
foreach ($ips as $value) {
if($ip == trim($value)){
die(“Sorry your IP is banned!”);
}
}
}

The problem is I want to have just one blockedIPs.txt located in the root directory so that all the web sites can access it and I only have to update 1 txt file and not multiple ones. I can’t seem to get this to work so any help would be appreciated.

Paul

You can use absolute server path to the file with blocked IPs. Like this:
[php]
$fp = fopen("/home/blockedIPs.txt",“r”);
[/php]

You can check what is the server path to root directory, for example using phpinfo().

Could you not block ip addresses using .htaccess file? stick your list of ips in there, bang it in your root directory and you should be laughing.

phphelp Thanks that worked perfectly. Paul

Sponsor our Newsletter | Privacy Policy | Terms of Service