Geo IP 定位
- 简介
- 安装/配置
- 预定义常量
- GeoIP 函数
- geoip_asnum_by_name — 获取自治系统号(ASN)
- geoip_continent_code_by_name — 获取七大洲的大写字母简称
- geoip_country_code_by_name — 获取国家代码
- geoip_country_code3_by_name — 获取三个字母组成的国家简称
- geoip_country_name_by_name — 获取国家的全称
- geoip_database_info — 获取 GeoIP 数据库的信息
- geoip_db_avail — GeoIP 数据库是否可用
- geoip_db_filename — 返回 GeoIP 数据库相对应的文件名
- geoip_db_get_all_info — 返回所有 GeoIP 数据库类型的详细信息
- geoip_domain_by_name — 获取二级域名
- geoip_id_by_name — 获取网络连接类型
- geoip_isp_by_name — 获取 ISP (网络服务提供商)的名称
- geoip_netspeedcell_by_name — 获取网络连接速度
- geoip_org_by_name — 获取机构的名称
- geoip_record_by_name — 返回 GeoIP 数据库中详细的城市信息
- geoip_region_by_name — 获取国家和地区代码
- geoip_region_name_by_code — 返回给定的国家和地区代码组合所对应的地区名称
- geoip_setup_custom_directory — 自定义 GeoIP 数据库的目录
- geoip_time_zone_by_country_and_region — 返回国家和地区的时区
+添加备注
用户贡献的备注 2 notes
mark at moderndeveloperllc dot com ¶
11 years ago
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/
webmaster at isag dot melbourne ¶
6 years ago
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");
$>