Need Help With foreach preg_match

Discussion in 'PHP' started by DjZoC, Jun 2, 2011.

  1. #1
    Hello there, i make this script but its not working how need to be ... hope someone can tell me what its the problem

      // ------------ Ip`s Not Allow
      $ips_class    = array(
       '66.249',
       '66.196'
      );
    
      foreach($ips_class as $ip_class)
      {
       echo $ip_class;
       if (!preg_match("~$ip_class~i", $_SERVER["REMOTE_ADDR"])) {
        $ip_status = "on";
    
       }
      }
    PHP:

     
    DjZoC, Jun 2, 2011 IP
  2. echipvina

    echipvina Active Member

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    You can use strpos replace preg_match
     
    echipvina, Jun 3, 2011 IP
  3. som3on3

    som3on3 Active Member

    Messages:
    138
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #3
    $ips_list = array('ip1', 'ip2', 'ip3');
    $ip_status = "off";
    if (!in_array($_SERVER["REMOTE_ADDR"], $ips_list)) {
        $ip_status = "on";
    }
    PHP:
    This is the simplest method
     
    som3on3, Jun 3, 2011 IP
  4. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    For some reason, I thought the reputation + comment thing displayed within a user's post. Regardless, follow ^ his advice. That method will be quicker on your server.
     
    ntomsheck, Jun 3, 2011 IP