<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Libre d'esprit &#187; géolocalisation</title>
	<atom:link href="http://libre-d-esprit.thinking-days.net/tag/geolocalisation/feed/" rel="self" type="application/rss+xml" />
	<link>http://libre-d-esprit.thinking-days.net</link>
	<description>Logiciels libres, joomla, talend, php, virtuemart, templates Joomla</description>
	<lastBuildDate>Sun, 21 Mar 2010 16:53:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Géolocaliser un utilisateur Facebook depuis PHP via mod_geoip de MaxMind</title>
		<link>http://libre-d-esprit.thinking-days.net/2009/10/geolocaliser-un-utilisateur-facebook-depuis-php-via-mod_geoip-de-maxmind/</link>
		<comments>http://libre-d-esprit.thinking-days.net/2009/10/geolocaliser-un-utilisateur-facebook-depuis-php-via-mod_geoip-de-maxmind/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 06:52:06 +0000</pubDate>
		<dc:creator>Antoine</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[géolocalisation]]></category>
		<category><![CDATA[maxmind]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://libre-d-esprit.thinking-days.net/?p=636</guid>
		<description><![CDATA[Cette fois-ci, rien à voir avec des templates Joomla / Virtuemart &#8230;;-)
Je souhaitais détecter dans une application Facebook, la localisation géographique de l&#8217;internaute. Pour cela je me suis tourné vers l&#8217;API de géolocalisation de MaxMind.
Facebook fonctionne comme un proxy. Quand un internaute se connecte sur Facebook pour utiliser une application tierce (quizz&#8230;.), Facebook se connecte [...]]]></description>
			<content:encoded><![CDATA[<p>Cette fois-ci, rien à voir avec des templates Joomla / Virtuemart &#8230;;-)</p>
<p>Je souhaitais détecter dans une application Facebook, la localisation géographique de l&#8217;internaute. Pour cela je me suis tourné vers l&#8217;API de géolocalisation de MaxMind.</p>
<p>Facebook fonctionne comme un proxy. Quand un internaute se connecte sur Facebook pour utiliser une application tierce (quizz&#8230;.), Facebook se connecte à son tour via HTTP à l&#8217;application tierce (qui peut être hébergé n&#8217;importe où). De ce fait, lorsque l&#8217;on essaye de géolocaliser un internaute en se basant sur l&#8217;adresse supposée de l&#8217;internaute, autrement dit l&#8217;adresse IP stockée dans la variable serveur REMOTE_ADDR, on géolocalise en réalité les serveurs de Facebook.</p>
<p>Heureusement, Facebook met à disposition l&#8217;adresse de l&#8217;internaute dans la variable serveur &laquo;&nbsp;HTTP_X_FB_USER_REMOTE_ADDR&nbsp;&raquo;.</p>
<p>Afin que la géolocalisation ne soit pas trop gourmande, j&#8217;ai préféré utiliser le module apache de Max Mind, et non la version PHP. Pour que la variable HTTP_X_FB_USER_REMOTE_ADDR soit prise en compte, il faut modifier le code de la façon suivante :</p>
<div class="codecolorer-container c dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/* (...) */</span><br />
ap_add_common_vars<span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* Récupération de l'adresse IP de l'utilisateur Facebook */</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>apr_table_get<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp;r<span style="color: #339933;">-&gt;</span>subprocess_env<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;HTTP_X_FB_USER_REMOTE_ADDR&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; ipaddr_ptr <span style="color: #339933;">=</span> <br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> apr_table_get<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;r<span style="color: #339933;">-&gt;</span>subprocess_env<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">&quot;HTTP_X_FB_USER_REMOTE_ADDR&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* Suite des tests */</span><br />
<br />
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>apr_table_get<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; r<span style="color: #339933;">-&gt;</span>subprocess_env<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ipaddr_ptr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> apr_table_get<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r<span style="color: #339933;">&gt;</span>subprocess_env<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #ff0000;">&quot;HTTP_CLIENT_IP&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #808080; font-style: italic;">/* (...) */</span></div></div>
<p>Pour que la partie de code ajoutée soit prise en compte, et donc que la gélocalisation Facebook fonctionne, il faut rajouter la ligne suivante dans votre configuration Apache.</p>
<div class="codecolorer-container text dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">GeoIPScanProxyHeaders On</div></div>
<p>Maintenant, la localisation géographique est accessible dans PHP, via ce type d&#8217;appel à apache_note :</p>
<div class="codecolorer-container php dawn" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// affiche la code du pays d'après l'adresse IP</span><br />
<span style="color: #b1b100;">echo</span> <a href="http://www.php.net/apache_note"><span style="color: #990000;">apache_note</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GEOIP_COUNTRY_CODE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://libre-d-esprit.thinking-days.net/2009/10/geolocaliser-un-utilisateur-facebook-depuis-php-via-mod_geoip-de-maxmind/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
