ip2location extension

The ip2location converts IP addresses to location data (country/city/longitude/latitude) using services available. Supported services are MaxMind.com and ip2location.com.

Configuration

Configuration is done by overriding the 'ip2location' entry from $mydbr_defaults. As an example, add following entry with your data into the user/defaults.php:

$mydbr_defaults['ip2location']= array(
  'default_service_provider' => 'maxmind',
  'maxmind' => array(
    'account_id' => 12345,
    'license_key' => 'abcdefg'
  ),
  'ip2location' => array(
    'api_key' => '12345',
    'package' => 'WS6'
  )
);

Commands

dbr.ip2location - Get IP location
dbr.ip2location.language - Maxmind can return names in different languages. If you wish to use other than English (code = 'en'), see supported languages from MaxMind

Syntax

select 'dbr.ip2location', 'save_procedure_name'[, 'maxmind' | 'ip2location']
select 'dbr.ip2location.language', language_code

Usage

The save procedure

The save procedure and allows you to save the data into desired location. The procedure has format of:

create procedure sp_geo_save_ip ( 
in_ip_address varchar(39),
in_country varchar(255),
in_city varchar(255),
in_latitude decimal(11,7),
in_longitude decimal(11,7),
in_isp varchar(255),
)
begin

insert ignore into my_ip2_location(ip_address, country, city , latitude, longitude, isp)
values ( in_ip_address, in_country, in_city , in_latitude, in_longitude, in_isp );

end

Convert IP addresses

select 'dbr.ip2location', 'sp_geo_save_ip';

select ip_address
from mydata;

Choose the service to use

select 'dbr.ip2location', 'sp_geo_save_ip', 'maxmind';

select ip_address
from mydata;

select 'dbr.ip2location', 'sp_geo_save_ip', 'ip2location';

select ip_address
from mydata;