Home > Geolocalisation, PHP > Geolocalisation PHP

Geolocalisation PHP

Aujourd’hui, au hasard du Web je suis tombé sur un outil qui permet de faire de la Géolocalisation en PHP grâce a Apache.

J’ai essayé cette méthode qui semble fonctionner. Il faut toutefois faire ses tests sur une machine en dehors du réseaux (une machine distante quoi).

Dans un premier temps, installer le module Apache qui va bien:

  • # apt-get install libapache2-mod-geoip

Rajoutez ceci au VirtualHost concerné par ce module:

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>

Redémarrez Apache:
  • # /etc/init.d/apache2 restart

Dans une nouvelle page PHP ajoutez ceci:

<html>
<body>
<?php
$country_name = apache_note("GEOIP_COUNTRY_NAME");
print "Country: " . $country_name;
?>
</body>
</html>

Et voila, rendez-vous sur la page et admirez :)
Categories: Geolocalisation, PHP Tags:
  1. No comments yet.
  1. No trackbacks yet.

Powered by WP Hashcash