note 25047 deleted from function.is-numeric by nlopess

From: Date: Sat, 24 Sep 2005 07:53:13 +0000
Subject: note 25047 deleted from function.is-numeric by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-95691@lists.php.net to get a copy of this message
Note Submitter: webmaster AT randomportal DOT com ---- This is going off on a tangent slightly but as it has been mentioned before I thought it might be an idea to add this, this is the function I use to verify the validity of IP address (takes only one input, the IP address string) function ip_check($ip) { $ip_array = explode(".", $ip); if (count($ip_array) <> 4) { $error = true; } for ($loop = 0; $loop < 4; $loop++) { if (is_numeric($ip_array[$loop]) != true) { $error = true; } if (strlen($ip_array[$loop]) > 3) { $error = true; } if ($ip_array[$loop] > 254) { $error = true; } if (($loop == 0) OR ($loop == 3)) { if ($ip_array[$loop] < 1) { $error = true; } } else { if ($ip_array[$loop] < 0) { $error = true; } } } There are probably a 101 other ways of doing this, but this one has worked for me

« previous php.notes (#95691) next »