Php application GeoIP Library instance tutorial Note that maxmind is the provider of the geoip database and provides sample and api instructions in many languages. For example, php and php's geoip library are quite different, including usage methods and interface functions. 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 series of. inc and. php environments that are not dependent on the environment. you only need to support php and directly use require. (Php GeoIP database entry instance) 1. GEOIP database: http://dev.maxmind.com/geoip/geoliteto Country: GeoLite Country to City: GeoLite City 2. download the dll from the official php geoip. dll Library http://windows.php.net/downloads/pecl/releases/geoip/1.0.8/modify php.ini and enable the geoiplibrary:
- Extension = php_geoip.dll
Append the geoip segment and specify the database location:
- [Geoip]
- Geoip. custom_directory = "D: \ php5.3 \ geo \"
Test code. Note that GeoIPCity. dat used in geoip. dll is GeoLiteCity. dat. Note the prompt when using it.
- 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 "));
3. documents and examples of the MaxMind official PHP file function library: http://dev.maxmind.com/geoip/downloadablemodify the sample in maxmind. geoIP in php and sample_city.php. dat/GeoLiteCity. the dat path uses ". /GeoIP. dat "or". /GeoLiteCity. dat. 1. detailed to country
- 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 );
2. go to the country city in detail
- 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-> longpolling. "\ 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-> longpolling. "\ n ";
- Print $ record-> metro_code. "\ n ";
- Print $ record-> area_code. "\ n ";
- Print $ record-> continent_code. "\ n ";
- Geoip_close ($ gi );
When using the above code, you can decide which code to use based on the development environment and the specific situation. |