Geo IP Location

Коментарии

It should be noted that this extension has now been superseded by the GeoIP2 API that MaxMind now produces. There is a pure-PHP set of classes and a C library and extension you can optionally install. The code can be found in various projects on MaxMind's GitHub page: https://github.com/maxmind/
2013-12-26 19:43:46
http://php5.kiev.ua/manual/ru/book.geoip.html
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 
GeoIp2\Database\Reader;
// 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 "\n");
print(
$record->country->name "\n");
print(
$record->country->names['zh-CN'] . "\n");
print(
$record->mostSpecificSubdivision->name "\n");
print(
$record->mostSpecificSubdivision->isoCode "\n");
print(
$record->city->name "\n");
print(
$record->postal->code "\n");
print(
$record->location->latitude "\n");
print(
$record->location->longitude "\n");
$>
2019-01-05 11:51:23
http://php5.kiev.ua/manual/ru/book.geoip.html
If you want to use the C Library 
Example for Ubuntu and PHP 7.4

sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
pecl install maxminddb
vi /etc/php/7.4/mods-available/maxmind.ini
add
extension=maxminddb.so
phpenmod maxmind

In code
<?php

use MaxMind\Db\Reader;

$ipAddress '24.24.24.24';
$databaseFile '/usr/share/GeoIP/GeoLite2-Country.mmdb';

$reader = new Reader($databaseFile);

// get returns just the record for the IP address
print_r($reader->get($ipAddress));

// getWithPrefixLen returns an array containing the record and the
// associated prefix length for that record.
print_r($reader->getWithPrefixLen($ipAddress));

$reader->close();
2022-01-27 20:51:58
http://php5.kiev.ua/manual/ru/book.geoip.html

    Поддержать сайт на родительском проекте КГБ