added check_ip

This commit is contained in:
Roland Gruber 2007-03-24 14:04:59 +00:00
parent 939217ac44
commit 1da2323f04
1 changed files with 30 additions and 0 deletions

View File

@ -591,5 +591,35 @@ function get_preg($argument, $regexp) {
return false;
}
/**
* This function checks if the given IP address ist valid.
*
* @param string IP to check
* @return boolean true or false
**/
function check_ip($ip) {
$part = split("[.]", $ip);
// Wenn... Keine 4 Segmente gefunden wurde
if (count($part) != 4) {
return false;
}
else {
// check each segment
for ($i = 0; $i < count($part); $i++) {
// only numbers are allowed
if (!is_numeric($part[$i])) {
return false;
}
else {
// segment must be smaller than 256
if($part[$i] > 255) {
return false;
}
}
}
}
return true;
}
?>