It should be noted that Maxmind is the provider of the GeoIP database,
It also provides sample and API documentation for many languages.
For example, PHP, and PHP GeoIP library is very different, including the use of the interface function.
The official PHP GeoIP needs to configure the PHP environment, load the Geoip.dll library, and specify the GeoIP library address in php.ini.
Maxmind provides a range of. Inc and. PHP is not dependent on the environment, as long as the support of PHP, direct require can be used.
One, GeoIP database
Http://dev.maxmind.com/geoip/geolite
Subdivision to Country: Geolite Country
Subdivided into cities: Geolite City
Second, the official PHP Geoip.dll Library
Download DLL http://windows.php.net/downloads/pecl/releases/geoip/1.0.8/
Modify php.ini to enable GEOIP libraries:
Copy Code code as follows:
Append GEOIP segment, specify database location:
Copy Code code as follows:
[GeoIP]
Geoip.custom_directory = "D:\php5.3\geo\"
Test code
Pay attention to the GeoIPCity.dat that is used in Geoip.dll, that is, GeoLiteCity.dat.
Copy Code code as follows:
Echo geoip_country_name_by_name ("8.8.8.8"). "\ n";
Print_r (Geoip_record_by_name ("8.8.8.8"));
Echo geoip_country_name_by_name ("61.139.2.69"). "\ n";
Print_r (Geoip_record_by_name ("61.139.2.69"));
Third, maxmind official PHP file function library
Documents and Examples: http://dev.maxmind.com/geoip/downloadable
Modify the Geoip.dat/geolitecity.dat path in sample.php and sample_city.php in the Maxmind example to your own path
The same directory uses "./geoip.dat" or "./geolitecity.dat".
Detailed to the country
Copy Code code as follows:
Include ("Geoip.inc");
$gi = Geoip_open ("./geoip.dat", Geoip_standard);
Echo geoip_country_code_by_addr ($gi, "8.8.8.8"). "\ T". GEOIP_COUNTRY_NAME_BY_ADDR ($gi, "8.8.8.8"). "\ n";
Echo geoip_country_code_by_addr ($gi, "61.139.2.69"). "\ T". GEOIP_COUNTRY_NAME_BY_ADDR ($gi, "61.139.2.69"). "\ n";
Geoip_close ($GI);
Detailed to the National city
Copy Code code as follows:
Include ("Geoipcity.inc");
Include ("geoipregionvars.php");
$gi = Geoip_open ("./geolitecity.dat", Geoip_standard);
$record = Geoip_record_by_addr ($gi, "8.8.8.8");
Print $record->country_code. " " . $record->country_code3. " " . $record->country_name. "\ n";
Print $record->region. " " . $GEOIP _region_name[$record->country_code][$record->region]. "\ n";
Print $record->city. "\ n";
Print $record->postal_code. "\ n";
Print $record->latitude. "\ n";
Print $record->longitude. "\ n";
Print $record->metro_code. "\ n";
Print $record->area_code. "\ n";
Print $record->continent_code. "\ n";
print "\ n-----\ n";
$record = Geoip_record_by_addr ($gi, "61.139.2.69");
Print $record->country_code. " " . $record->country_code3. " " . $record->country_name. "\ n";
Print $record->region. " " . $GEOIP _region_name[$record->country_code][$record->region]. "\ n";
Print $record->city. "\ n";
Print $record->postal_code. "\ n";
Print $record->latitude. "\ n";
Print $record->longitude. "\ n";
Print $record->metro_code. "\ n";
Print $record->area_code. "\ n";
Print $record->continent_code. "\ n";
Geoip_close ($GI);
Look at your own development environment and specific circumstances decide what kind of