Breve dica de como utilizar geoip no php

Posted by admin | Dicas, PHP | sexta-feira 30 outubro 2009 16:45

Precisei implementar o geoip junto a uma classe de usuários online, vou explicar a instalação e algumas funções.

Instalação
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
sudo mkdir -v /usr/share/GeoIP
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

sudo apt-get install php5-geoip

para utilizar a função pode executar php -a e o código abaixo ou basta chamar a função no seu script.
print_r(geoip_record_by_name(‘php.net’));

returns:
Array
(
[country_code] => US
[country_code3] => USA
[country_name] => United States
[region] => CA
[city] => Sunnyvale
[postal_code] => 94089
[latitude] => 37.4249000549
[longitude] => -122.007400513
[dma_code] => 807
[area_code] => 408
)

simples e rápido …..