Reply to Re: [PHP] function to compare ip addr to a ip range>

Your name:

Reply:


Posted by "Richard Lynch" on 10/13/05 20:23

On Thu, October 13, 2005 9:26 am, Bosky, Dave wrote:
> Does anyone have a function that will check if an ip address falls
> with
> a starting/ending ip address range>>

If you are using PostgreSQL, it has a built-in IP address data type
which almost for sure does this. :-)

Maybe what you want to do is just convert the IP to an integer.

function ipd($ip){
list($a, $b, $c, $c) = explode('.', $ip);
$ipd = $a * 0x1000000 + $b * 0x10000 + $c * 0x100 + $d;
return $ipd;
}

Now you can just compare idp() of any IP addresses to see if they are
in a 'range'

There's probably a better way.

And you should probably use bit-shifting operators (<< and >>) insted
of my * 0x1000000 method, as it might be faster.

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация