I have received some comments about `errors` in the script. These errors were simple warnings which should be disabled by any serious coder and were generated due to unproper mysql access setup or credentials. If you setup mysql access properly as mentioned in the Usage File it will work. I use it on site and it works. But it does require a little PHP skill to comprehend it and use it accordingly.
I made some changes to the ip2country php script class in order to help all those with no write access to directories, access needed to write the temporary files with ranges in the previous version of the ip2country script. It now runs a bit faster with only cUrl used to download ip2country IP ranges database files and no longer using ftp access for file retrieval.
I also made a few more changes listed below. Make sure you update the geolocation ip database when you get the new version as the internal table with country ip ranges has altered and is no longer compatible with old one.
First of all, this method to geolocate an IP is free, open-source and extremely easy to port to other Web Programming languages from the PHP Script Version or the IP2Country script presented here.
I provide here a Ip2Country PHP Class with very simple to use methods that will allow you to translate any IP address to a Country Code. The script will create an IP database with Countries and IP ranges which will be used for locating IP addresses.
The code consists of one easy to use, understand and integrate PHP class and works combined with a mySql table in a database you need to provide the class access to. It only has few functions you need to use, but you can use the mySql database table content to your requirements and add extra required functionality to help you in your specific task of geolocation.
The functionality concept is really easy. The top registrars have daily updated files stored containing all the IP ranges and country codes. Each country code will have at least one ip range allocated.
The files containing IP ranges are :
*Change {registry} to any of : ripe, arin, apnic, afrinic, lacnic
** ripencc is called ripe-ncc in ARIN registry.
ftp://ftp.{registry}.net/public/stats/arin/delegated-arin-latest
ftp://ftp.{registry}.net/public/stats/apnic/delegated-apnic-latest
ftp://ftp.{registry}.net/public/stats/afrinic/delegated-afrinic-latest
ftp://ftp.{registry}.net/public/stats/ripencc/delegated-ripencc-latest
ftp://ftp.{registry}.net/public/stats/lacnic/delegated-lacnic-latest
The internal format of the files is as follows :
arin|US|ipv4|69.80.224.0|4096|20060822|allocated
arin|US|ipv4|69.81.0.0|65536|20030926|allocated
arin|US|ipv4|69.82.0.0|131072|20031009|allocated
arin|US|ipv4|69.84.0.0|4096|20031022|allocated
arin|US|ipv4|69.84.32.0|4096|20031022|allocated
arin|US|ipv4|69.84.64.0|4096|20060705|allocated
You observe a pattern above.
{Registry}|{CountryCode}|{IPVersion4}|{IpAddressStart}|{IpRangeLength}|{AllocationDateYYYYMMDD}|{status}.
It is very easy to integrate the ip2country plugin and use in your site and in-depth understanding of how it works is not mandatory for proper usage of this free PHP ip2country script. Only basic PHP and mySql knowledge is required to use the ip2country script. No huge ip to country csv files are needed to perform ip to country lookup and this is a free ip to country method.
Post Feedback