Computer Hope

Internet & Networking => Web design => Topic started by: attroll on January 26, 2020, 12:04:48 PM

Title: Banning IP range in php file but need a way to allow IP command
Post by: attroll on January 26, 2020, 12:04:48 PM
I found another post on this forum that was very useful about banning IP in a PHP file.
I will attach the code below.
I do have a question about this code.
I am using IP Ranges in the ban.txt file.
Sometimes when doing this there is one IP within that range that is a user that does not need to be banned.
How can I add another text file of set it up in the PHP file to allowed IPs and have it override the ban.txt file?
Is this possible?
Code: [Select]
<?php
$userIp 
$_SERVER['REMOTE_ADDR'];
$ips file('/ban.txt');
$isBanned false;

foreach(
$ips as $ip) {
   
$split explode(','$ip);

   if(
$split[0] == $userIp)
      
$isBanned true;
      break;
}

if(!
$isBanned) {
  echo 
"It seems you have been banned from viewing this website.";
  echo 
"
"
;
  echo 
"If you think you have been banned in error please contact me.";
  exit();
}
?>