Codeigniter 3.x Library for accessing all APIs from GeoIP2 webservice client and database reader
This package provides an API for the GeoIP2 web services and databases. The API also works with the free GeoLite2 databases.
1.Download this archieve phar archive containing all of the dependencies for GeoIP2 from their release page the releases page.
Place it inside application/vendor/geo/ folder or any other folder you wish
Make sure you update your database path in the library if you decide to place it else where
2.Download the City Database for free from here GeoLite2 databases.
You can let the library guess your location
<?php
class YourAwesomeController extends CI_Controller{
public function get_geo(){
$this->load->library("CI_GeoIp2");
$reader = new CI_GeoIp2();
$reader->setIp();
print_r($reader->getCountry()); // Prints out "Tanzania" or any other country you are in
}
}or you can pass in any IP
$this->load->library("CI_GeoIp2");
$reader = new CI_GeoIp2();
$reader->setIp("123.456.789.10");
//if you want to manually extract objects
var_dump($reader->getRawRecord());
This code requires PHP 5.3 or greater. Older versions of PHP are not supported.
This software is Copyright (c) 2017 by Safi Cloud
CI GEO IP2 by Safi Cloud is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Permissions beyond the scope of this license may be available at saficloud.com/legal.
