View Single Post
Old 08-03-2007, 04:26 AM   #8 (permalink)
Kelvin
Recruit
 
Join Date: Aug 2007
Posts: 1
Kelvin is on a distinguished road
Just the function I needed, cheers sde.

1 slight possible improvement is removing the strstr, and instead checking explicitly (===) for 0 on strpos.

PHP Code:
function checkIP($ip_to_match$ip_array) {

  
// make sure this is an array before we use foreach
  
if (is_array($ip_array)) {

    
// loop through ip array
    
foreach ($ip_array as $ip) {

      
// first test if there is a match, then test if the match starts at the beginning
      
if (strpos($ip_to_match$ip)===0) {
        return 
true;
      }
    }
  }

  return 
false;

Kelvin is offline   Reply With Quote