| // | Guido Haeger | // +----------------------------------------------------------------------+ // // $Id: CheckIP.php,v 1.5 2002/08/17 09:41:24 mj Exp $ /** * Class to validate the syntax of IPv4 adresses * * Usage: * * * @author Martin Jansen * @author Guido Haeger * @package Net_CheckIP * @version 1.1 * @access public */ class Net_CheckIP { /** * Validate the syntax of the given IP adress * * This function splits the IP address in 4 pieces * (separated by ".") and checks for each piece * if it's an integer value between 0 and 255. * If all 4 parameters pass this test, the function * returns true. * * @param string $ip IP adress * @return bool true if syntax is valid, otherwise false */ function check_ip($ip) { $oct = explode('.', $ip); if (count($oct) != 4) { return false; } for ($i = 0; $i < 4; $i++) { if (!is_numeric($oct[$i])) { return false; } if ($oct[$i] < 0 || $oct[$i] > 255) { return false; } } return true; } } ?>