<?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; PHP</title>
	<atom:link href="http://libre-d-esprit.thinking-days.net/tag/php/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>
		<item>
		<title>Et BOM le script</title>
		<link>http://libre-d-esprit.thinking-days.net/2009/03/et-bom-le-script/</link>
		<comments>http://libre-d-esprit.thinking-days.net/2009/03/et-bom-le-script/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 21:35:08 +0000</pubDate>
		<dc:creator>Antoine</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[BOM]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[UTF-8]]></category>
		<category><![CDATA[UTF8]]></category>
		<guid isPermaLink="false">http://libre-d-esprit.thinking-days.net/?p=133</guid>
		<description><![CDATA[Il m&#8217;est arrivé à plusieurs reprises de devoir rechercher à plusieurs reprises un caractère BOM (marque d&#8217;ordre des octets : cf: wikipedia) au sein de sites web basés sur des logiciels libres tels que Joomla, WordPress..
La recherche de ce caractère dans l&#8217;ensemble des fichiers est bien entendu fastidieuse.
C&#8217;est pourquoi j&#8217;ai crée ce script qui recherche [...]]]></description>
			<content:encoded><![CDATA[<p>Il m&#8217;est arrivé à plusieurs reprises de devoir rechercher à plusieurs reprises un caractère BOM (marque d&#8217;ordre des octets : cf: <a href="http://fr.wikipedia.org/wiki/Marque_d%27ordre_des_octets">wikipedia</a>) au sein de sites web basés sur des logiciels libres tels que Joomla, WordPress..</p>
<p>La recherche de ce caractère dans l&#8217;ensemble des fichiers est bien entendu fastidieuse.</p>
<p>C&#8217;est pourquoi j&#8217;ai crée ce script qui recherche la présence de ces caractères au sein de tous les fichiers &laquo;&nbsp;.php&nbsp;&raquo;, &laquo;&nbsp;.html&nbsp;&raquo; et &laquo;&nbsp;.ini&nbsp;&raquo;  contenus dans la WEB_ROOT.</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: #000088;">$extensions_allowed</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$extensions_allowed</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'php'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$extensions_allowed</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'html'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$extensions_allowed</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ini'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> listeFichiers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$extensions_allowed</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/opendir"><span style="color: #990000;">opendir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/* Ceci est la façon correcte de traverser un dossier. */</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/readdir"><span style="color: #990000;">readdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">&lt;&gt;</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">&lt;&gt;</span><span style="color: #0000ff;">'..'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_file"><span style="color: #990000;">is_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</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; <span style="color: #000088;">$extension</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/pathinfo"><span style="color: #990000;">pathinfo</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$extension</span><span style="color: #339933;">,</span><span style="color: #000088;">$extensions_allowed</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; &nbsp; <span style="color: #000088;">$fileHandle</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$intro</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fread"><span style="color: #990000;">fread</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileHandle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileHandle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$intro</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xEF</span><span style="color: #660099; font-weight: bold;">\xBB</span><span style="color: #660099; font-weight: bold;">\xBF</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/<span style="color: #006699; font-weight: bold;">$file</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/flush"><span style="color: #990000;">flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #990000;">is_dir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</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; listeFichiers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<a href="http://www.php.net/closedir"><span style="color: #990000;">closedir</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/plain<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/set_time_limit"><span style="color: #990000;">set_time_limit</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> &nbsp;<a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
listeFichiers<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://libre-d-esprit.thinking-days.net/2009/03/et-bom-le-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
