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

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация