PHP code example of xp-forge / geoip
1. Go to this page and download the library: Download xp-forge/geoip library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xp-forge / geoip example snippets
use com\maxmind\geoip\GeoIpDatabase;
use io\File;
$database= GeoIpDatabase::open(new File('GeoLite2-City.mmdb'));
$record= $database->lookup('8.8.8.8');
$database->close();
// $record= com.maxmind.geoip.Record@{
// [city ] com.maxmind.geoip.Name(#5375480: Mountain View)
// [country ] com.maxmind.geoip.Name(#6252001: United States; code= US)
// [continent ] com.maxmind.geoip.Name(#6255149: North America; code= NA)
// [postalCode ] "94035"
// [location ] com.maxmind.geoip.Location(37.386,-122.0838; tz= America/Los_Angeles)
// [subdivisions] [com.maxmind.geoip.Name(#5332921: California; code= CA)]
// }