Latest Blog PostMon Dieu, les billets techniques refleuriraient-ils au printemps ? Si vous désirez récupérer des informations géographiques à partir de l’adresse IP (ou du hostname) d’un utilisateur, vous pouvez utiliser les fonctions fournies par l’extension PECL GeoIP.
Voici la procédure d’installation sur une Ubuntu 8.04:
$ sudo -s # apt-get install build-essential php5-dev php5-cli libgeoip-dev libgeoip1 php-pear # pecl install geoip
Si toiut s’est bien passé :
# echo "extension=geoip.so" >> /etc/php5/cli/php.ini
Si vous utilisez Apache comme serveur :
# echo "extension=geoip.so" >> /etc/php5/apache2/php.ini
Il faut également installer la base GeoIPCity de Maxmind :
# wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz # gunzip GeoLiteCity.dat.gz # mv GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
Vous pouvez maintenant tester l’extension avec une ligne du genre[1] :
$ echo "<?php var_dump(geoip_record_by_name('209.202.168.**'));"|php
Ça donne ici :
array(11) { ["continent_code"]=>
string(2) "NA"
["country_code"]=>
string(2) "US"
["country_code3"]=>
string(3) "USA"
["country_name"]=>
string(13) "United States"
["region"]=>
string(2) "NC"
["city"]=>
string(4) "Cary"
["postal_code"]=>
string(5) "27511"
["latitude"]=>
float(35.7********)
["longitude"]=>
float(-78.7*******)
["dma_code"]=>
int(560)
["area_code"]=>
int(919)
}
Enjoy.
[1] J’ai volontairement masqué certaines informations pour d’évidentes raisons de confidentialité.
Ce billet intitulé Utiliser les fonctions GeoIP de PHP sous Ubuntu a été rédigé par Nicolas Perriault et publié sur le blog Prendre un Café sous licence Creative Commons BY-NC-SA.
Published on 2009-06-02
MicrobloggingAbout 2 hours ago:
thanks for your kind support, people :) next step, start my company and find a house (help much appreciated btw)
About 4 hours ago:
wifey just had confirmation: she got a job in Montpellier! life's definitely going to change :)
About 8 hours ago:
I really hate all these digg-bar-likes, come on it's 2009
About 8 hours ago:
RT @denderello: RT @sfdaycgn: Update: The topic for the talk by Nicolas Perriault (@n1k0) will be "30 symfony Best Practices" #sfdaycgn
About 10 hours ago:
well, smells like sf2 could be coming faster than I thought :)
About 10 hours ago:
RT @hhamon, @fabpot: Meet the Symfony Octopus... the new Symfony Event Dispatcher component has just been released http://bit.ly/Xza69
1 day ago:
I don't have any feeling regarding the end of xhtml2wg, but this Italian salad was awesome
1 day ago:
can you feel the storm coming? can't wait, it's unbreathable here
1 day ago:
is fed up beeing green... back to colorful myself
1 day ago:
1h30 que je suis parti, je suis à peine à mi-chemin :(
1 day ago:
je crois que je fais une petite périphérite
1 day ago:
Celebrate 10 years of Moonfruit and win a MacBook Pro http://bit.ly/96bxC #moonfruit
2 days ago:
I WANT MY RIGHT-SIDE LABELS BACK IN GMAIL.
2 days ago:
#symfony users, this is a must read: http://bit.ly/gYFJR #bestpractices
2 days ago:
okay people, I didn't see the "forward all" on the right column, I'm tired ^^ thx for your help
2 days ago:
is it me or there's absolutely no way to forward a whole conversation in gmail?
3 days ago:
Fillon responsable du dopage ? http://twitpic.com/8xkhb http://bit.ly/WRDG6 (via @djgaston)
3 days ago:
entendu une chouette intervention sur les pôles de travail décentralisés à la française ce matin à la radio, ça a l'air de bouger
Bookmarks
Interestingness
Recent tracks