From 1da2323f040879fed3784b5b278560f4587fd914 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 24 Mar 2007 14:04:59 +0000 Subject: [PATCH] added check_ip --- lam/lib/account.inc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index d28a86e6..d7a8512d 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -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; +} + ?>