Skip to content

Instantly share code, notes, and snippets.



Last active Aug 24, 2016
What would you like to do?
GeoIP2 reader initialization
require_once 'vendor/autoload.php';
use GeoIp2\Database\Reader;
// Instantiate the "GeoIp2" Reader object
$reader = new Reader( get_template_directory() . '/GeoLite2-Country.mmdb' );
// Get country details for IP address
$result = $reader->country( '' )->country;
// Fetch the country ISO code
$country_iso_code = $result->isoCode;
// Fetch the country name
$country_name = $result->name;
// Displays the country ISO code
var_dump( $country_iso_code );
// Displays the name of the country
var_dump( $country_name );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.