Geo IP Location
- Introduction
- Installing/Configuring
- Predefined Constants
- GeoIP Functions
- geoip_asnum_by_name — Get the Autonomous System Numbers (ASN)
- geoip_continent_code_by_name — Get the two letter continent code
- geoip_country_code_by_name — Get the two letter country code
- geoip_country_code3_by_name — Get the three letter country code
- geoip_country_name_by_name — Get the full country name
- geoip_database_info — Get GeoIP Database information
- geoip_db_avail — Determine if GeoIP Database is available
- geoip_db_filename — Returns the filename of the corresponding GeoIP Database
- geoip_db_get_all_info — Returns detailed information about all GeoIP database types
- geoip_domain_by_name — Get the second level domain name
- geoip_id_by_name — Get the Internet connection type
- geoip_isp_by_name — Get the Internet Service Provider (ISP) name
- geoip_netspeedcell_by_name — Get the Internet connection speed
- geoip_org_by_name — Get the organization name
- geoip_record_by_name — Returns the detailed City information found in the GeoIP Database
- geoip_region_by_name — Get the country code and region
- geoip_region_name_by_code — Returns the region name for some country and region code combo
- geoip_setup_custom_directory — Set a custom directory for the GeoIP database.
- geoip_time_zone_by_country_and_region — Returns the time zone for some country and region code combo
Коментарии
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/
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");
$>