php geolocation package

Solutions on MaxInterview for php geolocation package by the best coders in the world

showing results for - "php geolocation package"
Sacha
16 Oct 2016
1
2With GeoIP2, the easiest way is to:
3
4* Grab the latest GeoIP2 Lite Database(s): https://dev.maxmind.com/geoip/geoip2/geolite2/
5* Grab the latest geoip2.phar: https://github.com/maxmind/GeoIP2-php/releases
6
7<?php
8require_once("geoip2.phar");
9use GeoIp2\Database\Reader;
10// City DB
11$reader = new Reader('/path/to/GeoLite2-City.mmdb');
12$record = $reader->city($_SERVER['REMOTE_ADDR']);
13// or for Country DB
14// $reader = new Reader('/path/to/GeoLite2-Country.mmdb');
15// $record = $reader->country($_SERVER['REMOTE_ADDR']);
16print($record->country->isoCode . "\n");
17print($record->country->name . "\n");
18print($record->country->names['zh-CN'] . "\n");
19print($record->mostSpecificSubdivision->name . "\n");
20print($record->mostSpecificSubdivision->isoCode . "\n");
21print($record->city->name . "\n");
22print($record->postal->code . "\n");
23print($record->location->latitude . "\n");
24print($record->location->longitude . "\n");
25$>
26
27