Geoip + php demonstration: Obtain country names and code through ip

Source: Internet
Author: User
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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.