• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

GeoIP PHP扩展安装与配置

php 搞代码 3年前 (2022-01-23) 18次浏览 已收录 0个评论
  作者:zhanhailiang 日期:2014-12-08

1. 安装依赖GeoIP-devel,GeoIP

GeoIP-devel.x86_64 : Development headers and libraries for GeoIPGeoIP.x86_64 : Library for country/city/organization to IP address or hostname mapping
yum install GeoIP.x86_64 GeoIP-devel.x86_64

2. 配置IP数据库GeoIP.dat,GeoLiteCity.dat

wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gzgunzip GeoIP.dat.gzmv GeoIP.dat /usr/local/share/GeoIP/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gzgunzip GeoLiteCity.dat.gzmkdir -v /usr/share/GeoIPmv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
说明 :GeoIPRegion.dat是付费服务;

参考:

  • http://dev.maxmind.com/geoip/legacy/install/country/

  • http://forum.directadmin.com/showthread.php?t=43309

  • 3. 安装扩展

    git clone [email protected]:billfeller/geoip.git; phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-geoipmake && make install

    4. 测试

    [root@~/wade/pecllearning/geoip]# /usr/local/php/bin/php -r 'print geoip_country_code3_by_name("220.181.112.244").PHP_EOL;'CHN[root@~/wade/pecllearning/geoip]# /usr/local/php/bin/php -r 'print_r(geoip_record_by_name("php.net"));'Array(    [continent_code] => NA    [country_c<div style="color:transparent">!本文来源gaodai.ma#com搞##代!^码网(</div><sup>搞gaodaima代码</sup>ode] => US    [country_code3] => USA    [country_name] => United States    [region] => CA    [city] => Fremont    [postal_code] => 94539    [latitude] => 37.51549911499    [longitude] => -121.8962020874    [dma_code] => 807    [area_code] => 510)

    注意,由于本地无GeoIPRegion.dat,调用 geoip_region_by_name 时会报Warning,如下

    [root@~/wade/pecllearning/geoip]# /usr/local/php/bin/php -r 'print geoip_region_by_name("220.181.112.244");'PHP Warning:  geoip_region_by_name(): Required database not available at /usr/share/GeoIP/GeoIPRegion.dat. in Command line code on line 1 Warning: geoip_region_by_name(): Required database not available at /usr/share/GeoIP/GeoIPRegion.dat. in Command line code on line 1

    搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
    转载请注明原文链接:GeoIP PHP扩展安装与配置
    喜欢 (0)
    [搞代码]
    分享 (0)
    发表我的评论
    取消评论

    表情 贴图 加粗 删除线 居中 斜体 签到

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址