Banning IP range in php file but need a way to allow IP command

Started by attroll, January 26, 2020, 12:04:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

attroll

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?
<?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();
}
?>