|
Posted by carmen on 05/08/06 08:33
Hello
I came across a php script on the net that will compare a web surfers IP
address to those in a text file. If a match or partial match is found, the
user is banned from accessing the php script, but if no match is found, the
php script executes.
The original script is as follows:
line 1 <?php
line 2 $IP = $_SERVER['REMOTE_ADDR'];
line 3 $IP_array = file('../folder/IP.dat');
line 4 $IP_array = str_replace("\n", "", $IP_array);
line 5 $IP_array = str_replace("\r", "", $IP_array);
line 6 foreach ($IP_array as $IP_test) {
line 7 if (substr_count($IP, $IP_test) != "0") {
line 8
line 9 echo 'Banned World!';
line 10
line 11 die();
line 12 }
line 13 }
line 14
line 15 echo 'Hello World!';
line 16
line 17 ?>
I currently have not one text file with banned addresses, but five different
one (eg IP.dat, IP1.dat, IP2.dat, IP3.dat, IP4.dat) and was wondering if
there was an easy way of changing the code so that it efficiently checks the
surfers IP address to all the IPx.dat files to see if it is banned? I could
simply replicate the code 5 times to check each file, but if there was a way
of just looping through the various files, that would be great.
I know I could merge the 5 IPx.dat files into a single one and not have to
worry about this, but for management purposes of the bans, it works a lot
better for me having the 5 distinct files.
Thank you
Navigation:
[Reply to this message]
|