PHP using GeoIP Library Instance _php Tutorial

Source: Internet
Author: User
Tags geoip geoip database maxmind
It is important to note that Maxmind is the provider of the GeoIP database,
Sample and API documentation are also available in many languages.
For example, PHP, and PHP GeoIP library is very different, including the use of the interface function.
PHP official GeoIP needs to configure the PHP environment, load the Geoip.dll library, and specify the GeoIP library address in php.ini.
Maxmind offers a range of. Inc and PHP for the environment, so long as PHP is supported, it can be used directly require.

I.. GEOIP database

Http://dev.maxmind.com/geoip/geolite
Subdivision to Country: GeoLite Country
Subdivided into cities: GeoLite City

Second, PHP official Geoip.dll Library

Download DLL http://windows.php.net/downloads/pecl/releases/geoip/1.0.8/
To modify php.ini, enable the GeoIP library:
Copy the Code code as follows: Extension=php_geoip.dll
Append GEOIP segment, specify database location:
Copy the Code code as follows: [GeoIP]
Geoip.custom_directory = "D:\php5.3\geo\"

Test code

Note that the GeoIPCity.dat that is used in Geoip.dll is GeoLiteCity.dat, use the time to look at the hint
Copy the 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

Documentation and Examples: http://dev.maxmind.com/geoip/downloadable
Modify the Geoip.dat/geolitecity.dat path in the Maxmind example in sample.php and sample_city.php to your own path
Use "./geoip.dat" or "./geolitecity.dat" in the same directory.
Detailed to the country
Copy the 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);

Details to the National city

Copy CodeThe code is 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 which kind of

http://www.bkjia.com/PHPjc/824763.html www.bkjia.com true http://www.bkjia.com/PHPjc/824763.html techarticle It is important to note that Maxmind is the provider of the GeoIP database, as well as the sample and API documentation for many languages. For example PHP, and PHP GeoIP library is very different, including the use of ...

  • Related Article

    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.