Creating IP to location based applications

Now a days people want data that is relative to them. This includes location specific dynamic data. There are two applications that I think have merit: ip2location and maxmind.

IP2location is $199 USD per server for the binary file to narrow an IP address down to the city level.

MaxMind is $370 per Site and $90/month for monthly updates of IP addresses.

I found the quality of MaxMind to be really good and precise. However, if you are tight for cash and want the features of providing dynamic data based on IP. I would stick with IP2Location. Below is a quick implementation of IP2location.

You need to download the IP2location class from: http://www.ip2location.com/download/PHP-IP2Location-4.11.zip

Then you need the DB4 file. The following link is a sample DB file that covers up to 99.255.255.255 range: http://www.ip2location.com/download/samples-db4.zip

Once you download the sample code. You’ll see the following:

require_once('ip2location.class.php');

$ip = new ip2location;
$ip->open(dirname(__FILE__) . '/IP-COUNTRY-REGION-CITY-ISP-SAMPLE.BIN');

$current_user_ip = $_SERVER['REMOTE_ADDR'];
$record = $ip->getAll($current_user_ip);

echo 'IP Address: ' . $record->ipAddress . '
';
echo 'IP Number: ' . $record->ipNumber . '
';
echo 'Country Short: ' . $record->countryShort . '
';
echo 'Country Long: ' . $record->countryLong . '
';
echo 'Region: ' . $record->region . '
';
echo 'City: ' . $record->city . '
';
echo 'ISP/Organisation: ' . $record->isp . '
';
echo 'Latitude: ' . $record->latitude . '
';
echo 'Longitude: ' . $record->longitude . '
';
echo 'Domain: ' . $record->domain . '
';
echo 'ZIP Code: ' . $record->zipCode . '
';
echo 'Time Zone: ' . $record->timeZone . '
';
echo 'Net Speed: ' . $record->netSpeed . '
';
echo 'IDD Code: ' . $record->iddCode . '
';
echo 'Area Code: ' . $record->areaCode . '
';
echo 'Weather Station Code: ' . $record->weatherStationCode . '
';
echo 'Weather Station Name: ' . $record->areaCode . '
';
echo 'MCC: ' . $record->mcc . '
';
echo 'MNC: ' . $record->mnc . '
';
echo 'Mobile Brand: ' . $record->mobileBrand . '
';
?>

Based on the sample code and the pricing that you’ve purchased. You will only be able to pin point the IP to the City level. So you can essentially ignore the remaining. You can further put this value into a cookie and verify that the user is in fact from this location or provide them with an option to change the location and update the cookie to that value. If they update that value then use that from now on rather than using ip2location. Another feature that can be used is creating a jsonp based REST service to provide the location based on ip for applications that you service outside of your domain.

Leave a Reply