Geoip + php example: obtain the country name and code GeoIP through ip Address & #43; PHP Usage Method 1: Download the GeoIP php file geoip. inc, save as geoip. inc. phpsjolzy. cnphpGeoIPbakgeoip. incphp code & lt ;? Phpinclude (& quot; geoip. inc. php & quo geoip + php example: get country name and code through ip
Use of GeoIP + PHP
Method 1:
Download the GeoIP PHP file geoip. inc and save it as geoip. inc. php.
Http://sjolzy.cn/php/GeoIP/bak/geoip.inc
Php code
Note: For local testing, the values of $ _ SERVER ['remote _ ADDR '] and $ _ SERVER ['remote _ ADDR'] may be 127.0.0.1, the output content is empty. You can test the IP address on your own.
Method 2:
Install GeoIP into PHP extension
Yum install GeoIP-data GeoIP-devel
Download GeoIP database
Wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
Gzip-d GeoLiteCity.dat.gz
Mv GeoLiteCity. dat/var/lib/GeoIP/GeoIPCity. dat
Download the PECL extension of GeoIP
Http://pecl.php.net/package/geoip
Http://pecl.php.net/get/geoip-1.0.7.tgz wget-c
Tar-zxvf geoip-1.0.7.tgz
Install PECL extension of GeoIP
Cd geoip-1.0.7
/Usr/local/php/bin/phpize
./Configure -- with-php-config =/usr/local/php/bin/php-config -- with-geoip
Make
Make install
Add
Extension = geoip. so
Restart php (nginx + php, but apache + php does not need to be restarted)
Now, you can use some GeoIP functions in the php Manual.
Http://cn.php.net/manual/en/book.geoip.php
Reference: http://blog.csdn.net/prince2270/article/details/4592753