PHP Classes
elePHPant
Icontem

CodeIgniter Geolocation Library: Get the location of an IP from a Web service

Recommend this page to a friend!
  Info   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-04-12 (4 years ago) RSS 2.0 feedNot enough user ratingsTotal: 582 This week: 1All time: 5,208 This week: 370Up
Version License PHP version Categories
ci-geolocation 1.0MIT/X Consortium ...5.3PHP 5, Web services, Geography
Description Author

This class can get the location of an IP from a Web service.

It can send HTTP requests to the Web server of a geo-location API to get the location of a given IP address either at country or city level.

The default configuration is set to retrieve the location using the ipinfodb Web service. The location results are returned as an array.

Name: Simo <contact>
Classes: 3 packages by
Country: Morocco Morocco
Age: ???
All time rank: 20143 in Morocco Morocco
Week rank: 202 Up1 in Morocco Morocco Up
Innovation award
Innovation award
Nominee: 1x

 

Details

CodeIgniter Geolocation Library

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

Installation

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.

Usage

You need to subscribe to http://ipinfodb.com/register.php 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->library('Geolocation');
$this->load->config('geolocation', true);

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

$this->geolocation->initialize($config);
$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();
var_dump($country);

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

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 : http://ipinfodb.com

  Files folder image Files  
File Role Description
Files folder imageapplication (2 files, 2 directories)
Files folder imagesystem (1 file)
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data
Accessible without login Plain text file version.json Data Auxiliary data

  Files folder image Files  /  application  
File Role Description
Files folder imageconfig (2 files)
Files folder imagelibraries (2 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Data Documentation

  Files folder image Files  /  application  /  config  
File Role Description
  Accessible without login Plain text file geolocation.php Conf. Configuration script
  Accessible without login HTML file index.html Data Documentation

  Files folder image Files  /  application  /  libraries  
File Role Description
  Plain text file Geolocation.php Class Class source
  Accessible without login HTML file index.html Data Documentation

  Files folder image Files  /  system  
File Role Description
  Accessible without login HTML file index.html Data Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:582
This week:1
All time:5,208
This week:370Up