文字

Geo IP Location

  • 简介
  • 安装/配置
    • 需求
    • 安装
    • 运行时配置
    • 资源类型
  • 预定义常量
  • GeoIP 函数
    • 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

用户评论:

[#1] istsehrgut [2015-05-08 06:00:26]

If you still want to use legacy binaries but also need IPv6 support this should help: 

In order to support IPv6->Country code easily and without unnecessary files based on the integration above:

Grab a copy of the latest legacy IPv6 data (I'm assuming you already have IPv4 binary):

wget http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz
Decompress and move it to a dir accessible to your web server:

gunzip GeoIPv6.dat
mv GeoIPv6.dat /etc/usr/share/GeoIP/GeoIPv6.dat
Grab a copy of geoip.inc from the Maxmind git dir (https://github.com/maxmind/geoip-api-php/blob/master/src/geoip.inc) and save it somewhere you can access wherever you'll need to run geoip.

If you have php5-geoip installed as I did, remove it with sudo apt-get remove php5-geoip; purge as necessary.

With the above done you can now test incoming IP address for v4 or v6 and get appropriate results.

Example:

<?php
include_once('geoip.inc');

//set an IPv6 address for testing
$ip='2601:8:be00:cf20:ca60:ff:fe09:35b5';


if((strpos($ip, ":") === false)) {
    //ipv4
    $gi = geoip_open("/usr/share/GeoIP/GeoIP1.dat",GEOIP_STANDARD);
    $country = geoip_country_code_by_addr($gi, $ip);
}
else {
    //ipv6
    $gi = geoip_open("/usr/share/GeoIP/GeoIPv6.dat",GEOIP_STANDARD);
    $country = geoip_country_code_by_addr_v6($gi, $ip);
}
echo $ip . "<br>" . $country;
This is specifically for Country, but can easily be replicated for City data.

[#2] mark at moderndeveloperllc dot com [2013-12-26 17:43:46]

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/

上一篇: 下一篇: