Re: function to compare ip addr to a ip range>
| From: | Greg Donald | Date: | Thu, 13 Oct 2005 14:53:25 +0000 |
| Subject: | Re: function to compare ip addr to a ip range> | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224043@lists.php.net to get a copy of this message | ||
On 10/13/05, Bosky, Dave <Dave.Bosky@htcinc.net> wrote:
> Does anyone have a function that will check if an ip address falls with
> a starting/ending ip address range>>
#!/usr/bin/php
<?php
$ip = '10.0.0.1';
$ip2 = '10.0.0.2';
$ip3 = '10.0.0.3';
$ip = abs( ip2long( $ip ) );
$ip2 = abs( ip2long( $ip2 ) );
$ip3 = abs( ip2long( $ip3 ) );
if( $ip2 > $ip && $ip2 < $ip3
|| $ip2 < $ip && $ip2 > $ip3 )
{
echo "In range\n";
}
else
{
echo "Not in range\n";
}
?>
--
Greg Donald
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/