Aller au contenu

Messages recommandés

Posté(e)

Voici une manière simple de logger vos visiteurs dans une table MySQL afin de les géolocaliser (hors accès mobile) sur le base du webservice : http://www.maxmind.c...javascript_city.

D'abord créer une table MySQL, Avec PhpMyAdmin importer la structure suivante :

(Il faut les privilèges en accès localserver)

Toutes informations stipulées dans la table seront loggées.


--

-- Structure de la table `geoloc`

--


CREATE TABLE IF NOT EXISTS `geoloc` (

  `DateHeure` timestamp NOT NULL default CURRENT_TIMESTAMP,

  `os` varchar(100) collate latin1_general_ci NOT NULL,

  `ip` varchar(100) collate latin1_general_ci NOT NULL,

  `host` varchar(120) collate latin1_general_ci NOT NULL,

  `pays` varchar(100) collate latin1_general_ci NOT NULL,

  `region` varchar(100) collate latin1_general_ci NOT NULL,

  `ville` varchar(100) collate latin1_general_ci NOT NULL,

  `latitude` float(10,6) NOT NULL,

  `longitude` float(10,6) NOT NULL,

  `index` int(10) NOT NULL auto_increment,

  PRIMARY KEY  (`index`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=0 ;


A la racine de votre site web, créer la page "geolocalisation.php" (page d'injection) avec le contenu suivant :

<?php



function OS($Agent=false)

{

	if(!$Agent) $Agent = $_SERVER['HTTP_USER_AGENT'];

	$os = null;

	$OS_arr = Array('Windows NT 6.0' => 'Windows Vista',

                	'Windows NT 6.1=> 'Windows 7',

                	'Windows NT 5.2' => 'Windows Server 2003',

					'Windows NT 5.1' => 'Windows XP',

					'Windows NT 5.0' => 'Windows 2000',

					'Win 9x 4.90' => 'Windows Me.',

					'Windows 98' => 'Windows 98',

					'Win98' => 'Windows 98',

					'Win95' => 'Windows 95',

					'Mac' => 'Macintosh',

					'PPC' => 'Macintosh',

					'Linux' => 'Linux',

					'FreeBSD' => 'FreeBSD',

					'Unix' => 'Unix',

					'SunOS' => 'SunOS',

					'IRIX' => 'IRIS',

					'BeOS' => 'BeOS',

					'OS/2' => 'OS/2',

					'AIX' => 'AIX');

	foreach($OS_arr as $key_OS => $value_OS)

	{

    	if(eregi($key_OS, $Agent))

    	{

        	$os = $value_OS;

    	}

	}

	if(empty($os)) return 'Inconnu';

	else return $os;

}

$sys = OS($_SERVER['HTTP_USER_AGENT']);

$host = gethostbyaddr($_SERVER['REMOTE_ADDR']); 

$con = mysql_connect('localhost','moncomptesql','motdepasse');

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("nomdelabase", $con);

$sql="INSERT INTO geoloc (os, ip, host, pays, region, ville, latitude, longitude)

VALUES

('$sys','$_SERVER[REMOTE_ADDR]','$host', '$_GET[pays]', '$_GET[region]', '$_GET[ville]', '$_GET[latitude]', '$_GET[longitude]')";

if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

mysql_close($con)

?>

Pour afficher la géocalisation du visiteur mettre dans votre page "index" le code suivant (par exemple en pied de page): geo.png

<fieldset  style="text-align:center;"><legend align="center">[ Visites et Geolocalisation de l'adresse IP ]</legend><p>


      L'adresse IP <font color="#000000"><b><script id='adr-ip' type="text/javascript" src="[url="http://www.actulab.com/affiche-ip.php"]http://www.actulab.com/affiche-ip.php[/url]" language="JavaScript"></script></b></font>

      <script language="JavaScript" src="[url="http://j.maxmind.com/app/geoip.js"]http://j.maxmind.com/app/geoip.js"></script[/url]>

      provient de

   	<font color="#000000"><b><script language="JavaScript">document.write(geoip_country_name());</script></b></font>

      à proximité de

   	<font color="#000000"><b><script language="JavaScript">document.write(geoip_city());</script></b></font>

      -&nbsp;Latitude:

   	<font color="#000000"><b><script language="JavaScript">document.write(geoip_latitude());</script></b></font>

      /&nbsp;Longitude:

      <font color="#000000"><b><script language="JavaScript">document.write(geoip_longitude());</script></b></font>

      <script language="JavaScript">var coord =(geoip_latitude()+","+geoip_longitude());</script>

      -<script language="JavaScript">document.write('<a href="[url="http://maps.google.fr/maps?f=q&amp;hl=fr&amp;geocode=&amp;q="]http://maps.google.fr/maps?f=q&amp;hl=fr&amp;geocode=&amp;q='+coord+'&amp;ie=UTF8&amp;ll='+coord+'&amp;z=13&amp;iwloc=addr&amp;source=embed[/url]" style="color:#0000FF;text-align:left" target="_blank">sur GoggleMaps</a>');</script>

      </p>

</fieldset>

A la suite dans votre page "index" ajouter le code suivant afin de logger dans la table les données affichées :

<script language="JavaScript">document.write('<script type="text/javascript" language="javascript" src="[url="http://host.domaine.fr/geolocalisation.php?region="]http://host.domaine.fr/geolocalisation.php?region='[/url]+ geoip_region()+ '&ville=' + geoip_city()+ '&pays=' + geoip_country_name()+ '&latitude=' + geoip_latitude()+ '&longitude=' + geoip_longitude()+ '">');</script></script>


Voilà pas très compliqué ... tongue.gif

Posté(e)

Ca marche je l'avais fait avec "awstats"...

Patrick

Qu'est-ce qui fonctionne ? Le tuto ? L'impl

Rejoindre la conversation

Vous pouvez publier maintenant et vous inscrire plus tard. Si vous avez un compte, connectez-vous maintenant pour publier avec votre compte.

Invité
Répondre à ce sujet…

×   Collé en tant que texte enrichi.   Coller en tant que texte brut à la place

  Seulement 75 émoticônes maximum sont autorisées.

×   Votre lien a été automatiquement intégré.   Afficher plutôt comme un lien

×   Votre contenu précédent a été rétabli.   Vider l’éditeur

×   Vous ne pouvez pas directement coller des images. Envoyez-les depuis votre ordinateur ou insérez-les depuis une URL.

×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer.