RE: ip-to-country - summary
| From: | Sandeep S. | Date: | Sun, 27 Apr 2003 14:37:51 +0000 |
| Subject: | RE: ip-to-country - summary | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-17120@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: Gabor Hojtsy [mailto:gabor@hojtsy.hu]
Well, I was unable to come up with anything better, then my indexable text file idea. What we need with this format:
- three fields: iprange from and to and three letter countrycode - have all fields padded to a fixed length (actually only the first two are related, and they should be padded with zeros added to the left to let PHP recognized them as numbers, if they need to act in a comparision) - no char to separate the fields. This is not needed because of the fixed width nature of the data - \n (one byte) linendingI have uploaded a file in the above format at the following location for you'll to try out: http://beta.ip-to-country.com/php.net/ip-to-country.zip The first two fields are 10 bytes each, therefore the fixed size of each record is (2*10+3+1) bytes. The file that was used to map the 2 letter alpha country codes to 3 letter alpha country codes is available at: http://beta.ip-to-country.com/php.net/Alpha2_to_Alpha3.txt
This way, one record will be (2*ipnumber_length+3+1) bytes. So we can build up an index for the IP numbers. This would mean that we need to define a step, with which we index the IP list. So something like:
$where_to_start_for_ip_search = array( 0 => 0, 10000 => 15, 20000 => 23,[...]);
This is a mapping between where (at what record) to start to search for an IP above that number. Then we can fseek() to that position, as we know the fixed size of records. From there we can start a normal linear search, that would probably be sufficient.Please feel free to contact me for additional information. Sandeep -- sandeep.s@directi.com