Reply
IP Lookup - best methods?
Old 07-15-2009, 11:16 PM IP Lookup - best methods?
!dahan!'s Avatar
Average Talker

Posts: 20
Trades: 0
We've been asked to create a special system for certain institutions to be recognised on a closed system by IP Address.

I'm just wondering what the best way would be to store an IP address range in the database so that I can easily get an institution id code from comparing the REMOTE_ADDR server variable against the stored range?

any ideas would be welcome
__________________
shoes in china
!dahan! is offline
Reply With Quote
View Public Profile Visit !dahan!'s homepage!
 
 
When You Register, These Ads Go Away!
Old 07-16-2009, 12:25 AM Re: IP Lookup - best methods?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
I haven't tried this, but maybe by taking out all the non-numbers and storing as a number? Computers are much faster at sifting through numbers than text. The key thing to making this successful would be ensuring that you stored 12.12.12.12 as 12012012012 so that entries are in proper numerical order.

EDIT: And, putting a UNIQUE index on the field.
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is online now
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-16-2009, 04:05 AM Re: IP Lookup - best methods?
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,069
Name: Matt
Location: Irvine, CA
Trades: 0
I agree with Jeremy that you should store IPs as numbers rather than strings. Another approach, rather than just dropping the decimal and adding a zero where necessary, would be to convert an IP to its decimal numeric equivalent.

An IP address is just a series of four 8-bit binary numbers. Given the full, 8-bit representation of each value, you can drop the decimals and convert the resulting 32-bit binary number to decimal. If you are using PHP there are two functions which will simplify this process for you:

http://us.php.net/manual/en/function.ip2long.php
http://us.php.net/manual/en/function.long2ip.php
__________________
Tinsology | How to Post Code | EverythingDev
NullPointer is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to IP Lookup - best methods?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.18734 seconds with 13 queries