PHP Classes


Recommend this page to a friend!
  Classes of Simo   CodeIgniter Geolocation Library   Download  
Role: Documentation
Content type: text/markdown
Description: Auxiliary data
Class: CodeIgniter Geolocation Library
Get the location of an IP from a Web service
Author: By
Last change: Update of
Date: 20 hours ago
Size: 1,564 bytes


Class file image Download

CodeIgniter Geolocation Library

CodeIgniter Geolocation library allows you to locate an IP Address using "ipinfodb" API.


CodeIgniter Versoin >= 2.x.x

Copy the file config/geolocation.php to the application/config folder.

Copy the file libraries/geolocation.php to the application/libraries folder.


You need to subscribe to to get your API KEY and then,

Open application/config/geolocation.php and put it there :

$config['api_key'] = 'YOUR_API_KEY';

After that, you can call the library within your controller for instance like following :

$this->load->config('geolocation', true);

$config = $this->config->config['geolocation'];

$this->geolocation->set_ip_address($ip); // IP to locate
// $this->geolocation->set_format('json');
// OR you can change the format within `config/geolocation.php` config file
$country = $this->geolocation->get_country();

// For more precision
$city = $this->geolocation->get_city();
if($city === FALSE)

Additional parameters

You can change the result format within the config file, or leave it empty to return a PHP Array

Open application/config/geolocation.php :

$config['format'] = 'json'; // available format : xml|raw|json  or empty for php array

IpInfoDb API :

For more information about the API please visit :