title: Checking visitors IP against a table of IPs. Some wildcards
body: <p>I have a script that loops through an array of IP's and checks the clients IP against them. </p>
  
  <pre><code>//filter IP address list
  $ip = array();
  $ip[] = '10.10.5.*';
  $ip[] = '234.119.260.65';
  $ip[] = '234.119.254.2';
  
  function testIP($ip){
  //testing that correct IP address used
  for($i=0, $cnt=count($ip); $i&lt;$cnt; $i++) {
      $ipregex = preg_replace(”/\./”, “\.”, $ip[$i]);
      $ipregex = preg_replace(”/\*/”, “.*”, $ipregex);
  
      if(preg_match('/'.$ipregex.'/', $_SERVER[REMOTE_ADDR])){
      // apply filter
      return true;
      }
      //do not apply filter
      return false;
  }
  </code></pre>
  
  <p>The thing is, I want my list of ip addresses to be in a table, and I want to make it as efficient as possible. The only way I can see of doing this is to SELECT * , and loop through each one in turn. Can anyone see a more efficient way of doing this? Perhaps on the MySQL side of things?</p>