feed Latest Blog Post

Utiliser les fonctions GeoIP de PHP sous Ubuntu

Mon 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.

Notes

[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

More articles from me

feed Microblogging

  • About 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

More twits from me

feed Bookmarks

mPDF Manual
mPDF is a PHP class which generates PDF files from UTF-8 encoded HTML
Tourist Remover
...removes unwanted objects from your photos!
SpringSource.org
Spring Roo provides interactive, lightweight (< 3 Mb download!), user customizable tooling that enables rapid delivery of high performance enterprise Java applications.
Neo4j - a Graph Database that Kicks Buttox | High Scalability
A graph is a collection nodes (things) and edges (relationships) that connect pairs of nodes. Slap properties (key-value pairs) on nodes and relationships and you have a surprisingly powerful way to represent most anything you can think of
neo4j open source graph database »
Neo4j is a graph database. It is an embedded, disk-based, fully transactional Java persistence engine that stores data structured in graphs rather than in tables.
Plugins | sfTwitterAuthPlugin | 1.0.3 | symfony | Web PHP Framework
Twitter authentication via OpenAuth. Also supports tweeting
EveryBlock source code released / The EveryBlock Blog
Today's a big day for us at EveryBlock. We're making our source code available.
boxy - Facebook-like dialog/overlay, with frills
Boxy is a flexible, Facebook-style dialog box for jQuery with support for dragging and size tweening
gdata-python-client - Google Code
The Google Data APIs (Google Data) provide a simple protocol for reading and writing data on the web.
Symfony Dependency Injection - Reinventing how you manage PHP classes
Symfony Dependency Injection is a PHP library that provides a lightweight and robust Dependency Injection Container for classes that implements the Dependency Injection pattern.

More bookmarks from me