Skip to content

Instantly share code, notes, and snippets.

@DomagojGojak

DomagojGojak/functions.php

Last active Aug 24, 2016
Embed
What would you like to do?
GeoIP2 reader initialization
<?php
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 78.134.247.178 IP address
$result = $reader->country( '78.134.247.178' )->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.