The same "checkipaddress" function posted by "lueck at gerwan dot de", with the add of an optional jolly char suport. Returns TRUE or FALSE
Results:
check_ip_address('125.32.15.0') is TRUE
check_ip_address('125.32.15.*') is FALSE
check_ip_address('125.32.15.*', '*') is TRUE
check_ip_address('*.*.*.*', '*') is TRUE
check_ip_address('125.-.15.2', '-') is TRUE
<?php
function check_ip_address($checkip, $jolly_char='') {
if ($jolly_char=='.') $jolly_char = '';
if ($jolly_char!='') {
$checkip = str_replace($jolly_char, '*', $checkip); $my_reg_expr = "^[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}\.[0-9\*]{1,3}$";
$jolly_char = '*';
}
else
$my_reg_expr = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$";
if (eregi($my_reg_expr, $checkip)) {
for ($i = 1; $i <= 3; $i++) {
if (!(substr($checkip, 0, strpos($checkip, ".")) >= "0" && substr($checkip, 0, strpos($checkip, ".")) <= "255")) {
if ($jolly_char!='') { if (substr($checkip, 0, strpos($checkip, "."))!=$jolly_char)
return false;
}
else
return false;
}
$checkip = substr($checkip, strpos($checkip, ".") + 1);
}
if (!($checkip >= "0" && $checkip <= "255")) { if ($jolly_char!='') { if ($checkip!=$jolly_char)
return false;
}
else
return false;
}
}
else
return false;
return true;
}
?>