php GeoIP library usage tutorial What is GepIP? The so-called GeoIP is to use the visitor's IP to locate his latitude and longitude, country/region, province, city, and even street location information. The technology here is not a difficult problem, the key lies in having an accurate database. With accurate data sources, you can earn a little money with rare goods, but what we pursue is to promote the spirit of cooperation and collective contribution for everyone to enjoy. How to use GeoIP? First we need data information, so we first obtain a free database: GeoIP.dat.gz, and then decompress it to get: GeoIP.dat. Then we perform on-demand operations on the data files. The example here uses PHP. GeoIP + PHP usage Method 1: Download the GeoIP PHP file geoip.inc. Download package
Note: If you test locally, because $_SERVER['REMOTE_ADDR'] and $_SERVER['REMOTE_ADDR '] may be 127.0.0.1, so the output content is empty. You can bring your own IP for testing Method 2: Install GeoIP as a PHP extension
Download GeoIP database
Download GeoIP’s PECL extension Download address http://pecl.php.net/package/geoip
Install GeoIP PECL extension
and add it to php.ini extension=geoip.so Then just restart php. Then, you can use some of the GeoIP functions in the php manual. |