PHP7 GeoIP扩展

GeoIP是一个根据IP地址查询位置的API的集成。它支持对国家、地区、城市、纬度和经度的查询。

安装GEO IP 扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#: yum
yum install GeoIP GeoIP-devel

#: GeoIP Data
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz

#: Install
git clone https://github.com/Zakay/geoip.git && cd geoip

/software/php/bin/phpize
./configure --with-php-config=/software/php/bin/php-config --with-geoip
make && make install

#: geoip.so
php/lib/php/extensions/no-debug-non-zts-20151012/

#: php.ini
extension=geoip.so

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
php -r 'print_r(geoip_record_by_name(""));'
Array
(
[continent_code] => AS
[country_code] => HK
[country_code3] => HKG
[country_name] => Hong Kong
[region] =>
[city] =>
[postal_code] =>
[latitude] => 22.25
[longitude] => 114.16670227051
[dma_code] => 0
[area_code] => 0
)