You are here: PHP IP blocking script is not working... « PHP Programming Language « IT news, forums, messages
PHP IP blocking script is not working...

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация