GeoIP Introduction: What is GepIP? GeoIP is used to locate the geographical longitude and latitude of a visitor, country, region, province, city, or even street.
GeoIP introduction: What is GepIP?
GeoIP is used to locate the geographical longitude and latitude of a visitor, country/region, province/city, or even street. The technology here is not difficult. The key is to have a precise database. With accurate data sources, you can earn a small amount of money for odd goods. However, it is our pursuit to promote the spirit of cooperation and make a collective contribution to everyone's enjoyment.
How to use GeoIP? First, we need data information, so we first get a free database: GeoIP.dat.gz, and then decompress it to get: GeoIP. dat, followed by on-demand operations on data files. The example here uses PHP.
Use of GeoIP + PHP Method 1:
Download the GeoIP PHP file geoip. inc. Package download
The code is as follows:
Include ("geoip. inc. php ");
// Open the data file
$ Gi = geoip_open ("GeoIP. dat", GEOIP_STANDARD );
// Obtain country code
$ Country_code = geoip_country_code_by_addr ($ gi, $ _ SERVER ['remote _ ADDR ']);
Echo "Your country code is: $ country_code ";
// Obtain the country name
$ Country_name = geoip_country_name_by_addr ($ gi, $ _ SERVER ['remote _ ADDR ']);
Echo "Your country name is: $ country_name ";
// Close the file
Geoip_close ($ gi );
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.
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.
Now, you can use some GeoIP functions in the php Manual.
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