|
Posted by Franηoise Debat on 01/24/07 09:30
Hello,
I wonder if anybody can help. I have an IP blocking script which
displays a blank screen if an IP is detected from a list in an external
file. The problem is, the script only reads the last IP¨in the file, not
every one. Can somebody tell me where this is going wrong?
<?php
//get user's IP address
$userip = $_SERVER['REMOTE_ADDR'];
//get list of banned IPs from external file
$filename="http://www.mysite.com/banned.txt";
$bannedlist = array();
$file = fopen($filename, "r");
while(!feof($file)) {
//read file line by line into a new array element
$bannedlist[] = fgets($file, 4096);
}
fclose ($file);
//check if the current user's IP is in the banned list
if (in_array($userip, $bannedlist))
{
//it is, so send him packing
echo "This website is currently unavailable";
exit();
}
//continue executing the script
?>
The banned.txt file is simple a list of IPs, one per line, as follows:
82.207.17.160
84.235.100.2
87.118.106.177
193.69.180.120
84.244.7.168
I update it using Dreamweaver and upload to my site.
If anybody could help with this I would be grateful. Thank you
Françoise
[Back to original message]
|