geoip php

From WebHostingNeeds.com
Jump to: navigation, search

Install php-pecl-geoip from epel

yum install php-pecl-geoip

Download City DB.

cd /usr/share/GeoIP/
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
mv GeoLiteCity.dat GeoIPCity.dat

MaxMind update free DB once per month.

Sample code

<?php
$ip = 'IP_HERE';
echo '<pre>';
echo "\n\ngeoip_country_code_by_name\n\n";
print_r(geoip_country_code_by_name($ip));
echo "\n\ngeoip_record_by_name   \n\n";
print_r(geoip_record_by_name   ($ip));

Result

geoip_country_code_by_name

IN

geoip_record_by_name   

Array
(
    [continent_code] => AS
    [country_code] => IN
    [country_code3] => IND
    [country_name] => India
    [region] => 13
    [city] => Kochi
    [postal_code] => 
    [latitude] => 9.9666996002197
    [longitude] => 76.233299255371
    [dma_code] => 0
    [area_code] => 0
)



geoip

php