Re: function to compare ip addr to a ip range

From: Date: Thu, 13 Oct 2005 15:38:48 +0000
Subject: Re: function to compare ip addr to a ip range
Groups: php.general 
Request: Send a blank email to php-general+get-224054@lists.php.net to get a copy of this message
You could try converting to long IP addresses and comparing that way: <?php // To actually get the long IP address that you can use in http:// // you sometimes need to use something like printf("%u\n", ip2long($ip)); // See also: http://us3.php.net/manual/en/function.ip2long.php $startip = "192.168.0.5"; $endip = "192.168.0.16"; $targetip = "192.168.0.7"; $startlong = ip2long($startip); $endlong = ip2long($endip); $targetlong = ip2long($targetip); if ($startlong <= $targetlong AND $targetlong <= $endlong) echo "within range"; else echo "out of range"; ?> = = = Original message = = = Does anyone have a function that will check if an ip address falls with a starting/ending ip address range>> Thanks, Dave ___________________________________________________________ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com.

« previous php.general (#224054) next »