How to install GeoIp module for PHP


How to install GeoIp module for PHP on Windows

Step 1: Download GeoIP release at here

Ex: for PHP 5.4 http://windows.php.net/downloads/pecl/releases/geoip/1.0.8/php_geoip-1.0.8-5.4-ts-vc9-x86.zip

Step 2: extract file php_geoip.dll then place it in your extension folder like: D:\AppServ\php5\ext

php_geoip.dll

php_geoip.dll location

Step 3: Download file GeoLiteCity.dat.gz

Step 4: extract file GeoLiteCity.dat and rename it to GeoIPCity.dat

Step 5: Place this file to any folder like: D:\AppServ\php5\

Step 6: Open file php.ini then add some lines:

extension=php_geoip.dll

php ini geoip

[geoip]
geoip.custom_directory = D:\AppServ\php5\

php ini geoip 2

Step 7: restart Apache

Now you can use GeoIP

geoip extension

Example usage:

<?php

/**
 * @author tutorialspots.com
 * @copyright 2016
 */

print_r(geoip_record_by_name('tutorialspots.com'));

?>

Result:

Array
(
    [continent_code] => NA
    [country_code] => US
    [country_code3] => USA
    [country_name] => United States
    [region] => IL
    [city] => Aurora
    [postal_code] => 60502
    [latitude] => 41.7606010437
    [longitude] => -88.320098877
    [dma_code] => 602
    [area_code] => 630
)

Note: to use function geoip_org_by_name you must have the file GeoIPOrg.dat, you can download it here:

https://github.com/maxmind/geoip-api-php/blob/master/tests/data/GeoIPOrg.dat?raw=true
or
https://github.com/nateweiss/geoip-data-files/blob/master/GeoIPOrg.dat?raw=true

1 Comment

Leave a Reply