Reply to Re: [PHP] Converting IP Address to int value?

Your name:

Reply:


Posted by John Nichel on 10/16/91 11:36

Jay Paulson (CE CEN) wrote:
> I'm in the process of parsing through a apache access_log file and putting the information into a database. Right now I have the ip addresses going into a database as a character format xxx.xxx.xxx.xxx and then later I'm creating my queries to search for ip addresses xxx.xxx.%, which I think is really ineffecient. Therefore, I wanted to add a new field in my database which would be just an int value and have php convert the ip address to an int for database insertion. Then have an sql query that would just convert that int back into an ip address if I needed. My ultimate goal is to be able to write a query simular to this:
>
> SELECT * FROM Apache_Stats WHERE int_ip BETWEEN INET_ATON('xxx.xxx.0.0') AND INET_ATON ('xxx.xxx.255.255')
>
> Is there a function in PHP that will convert the xxx.xxx.xxx.xxx ip address to the same number that INET_ATON() is converting it to? I know about ip2long() but in the PHP docs it doesn't convert right unles you use the printf("%u...) function.
>
> Thanks!
>

$ip_int = sprintf ( "%u", ip2long ( $ip_dotted ) );

$ip_dotted = sprintf ( "%s", long2ip ( - ( 4294967296 - $ip_int ) ) );

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnichel@dotcomholdingsofbuffalo.com

[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

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