Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php geolocation package


With GeoIP2, the easiest way is to:

* Grab the latest GeoIP2 Lite Database(s): https://dev.maxmind.com/geoip/geoip2/geolite2/
* Grab the latest geoip2.phar: https://github.com/maxmind/GeoIP2-php/releases

<?php
require_once("geoip2.phar");
use GeoIp2DatabaseReader;
// City DB
$reader = new Reader('/path/to/GeoLite2-City.mmdb');
$record = $reader->city($_SERVER['REMOTE_ADDR']);
// or for Country DB
// $reader = new Reader('/path/to/GeoLite2-Country.mmdb');
// $record = $reader->country($_SERVER['REMOTE_ADDR']);
print($record->country->isoCode . "
");
print($record->country->name . "
");
print($record->country->names['zh-CN'] . "
");
print($record->mostSpecificSubdivision->name . "
");
print($record->mostSpecificSubdivision->isoCode . "
");
print($record->city->name . "
");
print($record->postal->code . "
");
print($record->location->latitude . "
");
print($record->location->longitude . "
");
$>

Source by www.php.net #
 
PREVIOUS NEXT
Tagged: #php #geolocation #package
ADD COMMENT
Topic
Name
3+9 =