foreach problems.... Banned IP list
Posted: Sat Mar 08, 2008 8:16 pm
I have a file with banned IP addresses. I want to be able to delete addresses in the list with a GET.
The file looks like this:
333.333.333.333
555.53.553.333
11.33.444.888
etc.....
The script I have tried looks like this:
I am trying to write the IPs that are not equal to the GET variable to another file and then copy that file to the original at the end, however, ALL addresses are written. The if statement is always executed.
Any thoughts???
Thanks!
The file looks like this:
333.333.333.333
555.53.553.333
11.33.444.888
etc.....
The script I have tried looks like this:
Code: Select all
<?
$ip = $_GET['ip'];
$handle = fopen("ip2.php", "w");
foreach(file("ip.php") as $value){
if($value != $ip){ fwrite($handle, $value);
}
}
fclose($handle);
copy("ip2.php", "ip.php");
?>Any thoughts???
Thanks!