Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Banning IP range in php file but need a way to allow IP command  (Read 84382 times)

0 Members and 1 Guest are viewing this topic.

attroll

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Banning IP range in php file but need a way to allow IP command
    « 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();
    }
    ?>