<?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>EXinsidePHP</title>
	<atom:link href="http://www.exinsidephp.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.exinsidephp.com</link>
	<description>Développeur Web avant tout...</description>
	<lastBuildDate>Fri, 21 Oct 2011 14:31:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>MAJ &#8211; Créer dynamiquement un bouton Paypal sécurisé</title>
		<link>http://www.exinsidephp.com/2011/08/30/creer-dynamiquement-un-bouton-paypal-securise/</link>
		<comments>http://www.exinsidephp.com/2011/08/30/creer-dynamiquement-un-bouton-paypal-securise/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 10:10:34 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[PHP5/POO]]></category>
		<category><![CDATA[Sécurité]]></category>
		<category><![CDATA[IPN]]></category>
		<category><![CDATA[OpenSSL]]></category>
		<category><![CDATA[Paypal]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=355</guid>
		<description><![CDATA[Il existe une multitude de possibilités pour faire un bouton de paiement Paypal, la plus courante est de créer le bouton dans l&#8217;interface de celui-ci et de copier coller le code qu&#8217;il vous donne au final sur votre page. Le défaut de cette méthode c&#8217;est que l&#8217;on doit créer un bouton pour chaque objet que]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/04/paypal_03.gif"><img class="alignleft size-full wp-image-356" title="Paypal" src="http://www.exinsidephp.com/wp-content/uploads/2010/04/paypal_03.gif" alt="" width="300" height="220" /></a>Il existe une multitude de possibilités pour faire un bouton de paiement Paypal, la plus courante est de créer le bouton dans l&#8217;interface de celui-ci et de copier coller le code qu&#8217;il vous donne au final sur votre page. Le défaut de cette méthode c&#8217;est que l&#8217;on doit créer un bouton pour chaque objet que l&#8217;on vend, la flexibilité n&#8217;est donc pas au rendez vous avec cette méthode. La deuxième méthode utilisée est la possibilité de créer un formulaire avec les paramètres définis sur <a title="Documentation Paypal" href="https://www.paypal-france.fr/webscr/fr_FR/html/Espace-Integration-PayPal/ic_std-variable-reference.html" target="_blank">cette page</a>. Avec cette méthode la flexibilité est présente mais pas la sécurité. En effet il est alors facile de modifier le prix du panier dans le formulaire avec l&#8217;extension <a title="Firebug" href="https://addons.mozilla.org/fr/firefox/addon/1843" target="_blank">Firebug</a> de Firefox et ainsi falsifier le prix à payer&#8230; Si la cohérence des informations n&#8217;est pas vérifiée lors du feedback de Paypal (IPN) c&#8217;est un réel problème !</p>
<p>Je vais donc vous présenter la méthode permettant de générer le bouton Paypal avec un cryptage SSL des données du formulaire vous garantissant un paiement sécurisé de bout en bout&#8230; Attention tout de même cette méthode n&#8217;est pas à la portée de tout le monde car il y a certaines contraintes techniques.</p>
<p><span id="more-355"></span>Comme je le disais il existe des contraintes techniques et votre environnement doit répondre aux besoins suivants :</p>
<blockquote>
<ul>
<li>Un accès à la fonction <a title="Documentation PHP Exec" href="http://fr.php.net/manual/en/function.exec.php" target="_blank">exec</a> de PHP (exit si votre environnement est configuré en safe_mode à on) ou équivalent.</li>
<li>Avoir un accès SSH en ligne de commande (Pour pouvoir générer les certificats SSL, même si je pense qu&#8217;ils peuvent être générés sur votre machine et envoyés ensuite sur votre serveur)</li>
<li>Avoir OpenSSL d&#8217;installé sur le serveur</li>
</ul>
</blockquote>
<p><strong><span style="color: #993300;">Etape 1 &#8211; Génération des certificats SSL</span></strong></p>
<p>Connectez vous en SSH sur votre serveur. Si OpenSSL n&#8217;est pas installé sur celui-ci, installez le avec cette commande (si vous êtes sous Debian) :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> openssl</pre></div></div>

<p>Si vous n&#8217;avez pas d&#8217;accès à SSH vous pouvez toujours installer OpenSSl sur votre poste sous Windows avec les binaires <a title="Binaires OpenSSL" href="http://www.openssl.org/related/binaries.html">disponibles ici</a>.</p>
<p><strong>NB: </strong>Dans la suite de l&#8217;article je n&#8217;expliquerais pas les commandes sous Windows mais normalement il suffira de vous placer dans le répertoire où l&#8217;exécutable OpenSSL.exe est situé et de remplacer les commandes &laquo;&nbsp;openssl&nbsp;&raquo; par &laquo;&nbsp;openssl.exe&nbsp;&raquo;.</p>
<p>Pour commencer mettez vous dans un répertoire disponible par FTP (Il faudra par la suite télécharger un certificat pour l&#8217;envoyer à Paypal). Ensuite tapez cette commande pour générer la clé privée :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl genrsa <span style="color: #660033;">-out</span> clepriv.pem <span style="color: #000000;">1024</span></pre></div></div>

<p>Puis cette commande pour générer le certificat publique :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl req <span style="color: #660033;">-new</span> <span style="color: #660033;">-key</span> clepriv.pem <span style="color: #660033;">-x509</span> <span style="color: #660033;">-days</span> <span style="color: #000000;">365</span> <span style="color: #660033;">-out</span> certpub.pem</pre></div></div>

<p>Remplissez les informations demandées (Pays, Email etc&#8230;).</p>
<p><strong>Note importante : </strong>Le certificat sera ici valable 1 an, il faudra donc penser que dans un an vous devrez re-générer ce certificat ! Vous pouvez augmenter la durée de vie de celui-ci mais ce n&#8217;est pas particulièrement recommandé.</p>
<p><strong><span style="color: #993300;">Etape 2 &#8211; Envoyer le certificat publique à Paypal et télécharger le certificat publique de Paypal</span></strong></p>
<p>Maintenant il faut envoyer le certificat publique de votre site à Paypal (certpub.pem) et télécharger le certificat publique de Paypal. Pour se faire connectez vous sur votre compte Paypal et allez dans :</p>
<ul>
<li><strong>Mon Compte </strong><strong>=&gt;  Préférences =&gt; Plus d&#8217;Options =&gt; Certificats de cryptage pour site marchand</strong> (colonne de droite, en bas)</li>
</ul>
<p>Commencez par télécharger le certificat publique de Paypal en cliquant sur le bouton &laquo;&nbsp;Télécharger&nbsp;&raquo;. Vous aurez un fichier qui se nomme <strong>paypal_cert_pem.txt</strong>, renommez le en <strong>paypal_cert.pem</strong>.</p>
<p>En bas de page, dans la partie <strong>&laquo;&nbsp;</strong><strong>Vos certificats publics&nbsp;&raquo; </strong>cliquez sur le bouton &laquo;&nbsp;Ajouter&nbsp;&raquo; et sélectionnez le fichier <strong>certpub.pem </strong>que vous avez précédemment généré. Vous reviendrez ensuite sur la page de gestion des certificats et vous devriez voir apparaitre une ligne dans le tableau du bas avec comme informations l&#8217;ID du certificat, l&#8217;autorité de certification (correspondant aux informations saisies lors de la génération de votre certificat publique) et la date d&#8217;expiration de celui-ci. <strong>Noter dans un coin l&#8217;ID du certificat indiqué il servira par la suite.</strong></p>
<p>A cette étape vous aurez donc en votre possession trois fichiers :</p>
<ul>
<li>certpub.pem</li>
<li>clepriv.pem</li>
<li>paypal_cert.pem</li>
</ul>
<p><strong><span style="color: #993300;">Etape 3 &#8211; Mise en place de la génération du bouton en PHP</span></strong></p>
<p><span style="color: #993300;"><span style="color: #000000;">Tout d&#8217;abord placez les trois fichiers pem dans un répertoire de votre serveur <strong>inaccessible par le web</strong>, pour être plus explicite il doit être en dehors de la racine HTTP de votre serveur mais il doit toujours être accessible par PHP. Si l&#8217;option open_base_dir est active sur votre configuration PHP ajoutez ce répertoire pour que PHP puisse y accéder. Si vous ne pouvez pas modifier cette configuration, vous pouvez éventuellement placer les fichiers dans un répertoire de votre site mais vous devrez mettre un .htaccess empêchant l&#8217;accès à ces fichiers. Votre .htaccess ressemblera à ceci :</span></span></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Options</span> -<span style="color: #0000ff;">Indexes</span>
&lt;<span style="color: #000000; font-weight:bold;">Files</span> ~ <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(pem)$&quot;</span>&gt;
 	<span style="color: #00007f;">order</span> <span style="color: #00007f;">deny</span>,<span style="color: #00007f;">allow</span>
 	<span style="color: #00007f;">deny</span> from <span style="color: #0000ff;">all</span>
&lt;/<span style="color: #000000; font-weight:bold;">Files</span>&gt;</pre></div></div>

<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1014px; width: 1px; height: 1px; overflow: hidden;">
<pre>Options -Indexes</pre>
</div>
<p>A noter que pour un serveur Apache supérieur à la version 1.3 il vaut mieux utiliser :</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">Options</span> -<span style="color: #0000ff;">Indexes</span>
&lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>(pem)$&quot;</span>&gt;
 	<span style="color: #00007f;">order</span> <span style="color: #00007f;">deny</span>,<span style="color: #00007f;">allow</span>
 	<span style="color: #00007f;">deny</span> from <span style="color: #0000ff;">all</span>
&lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;</pre></div></div>

<p>Maintenant il faut générer le bouton en php, pour faire ceci je vais vous fournir une petite classe PHP5 vous permettant de vous simplifier la vie. Créez un fichier qui se nomme <strong>PaypalCrypt.class.php</strong> et mettez ceci dedans :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> PaypalCrypt<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$privateKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$publicKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$paypalKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$pathOpenSSL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/bin/openssl'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'bn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Boutique_BuyNow_WPS_FR'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'cmd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'_xclick'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'lc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'FR'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'custom'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'invoice'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'currency_code'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'EUR'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'charset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//Définit le charset utilisé sur le site</span>
        <span style="color: #0000ff;">'no_shipping'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Nothing</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPrivateKey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$privateKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">privateKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$privateKey</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPublicKey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$publicKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publicKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$publicKey</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setPaypalKey<span style="color: #009900;">&#40;</span><span style="color: #000088;">$paypalKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paypalKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paypalKey</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getCryptedData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">privateKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR: MY_KEY_FILE '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">privateKey</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publicKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR: MY_CERT_FILE '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">publicKey</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paypalKey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR: PAYPAL_CERT_FILE '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">paypalKey</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$openssl_cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$this-&gt;pathOpenSSL</span>  smime -sign -signer <span style="color: #006699; font-weight: bold;">$this-&gt;publicKey</span>  -inkey <span style="color: #006699; font-weight: bold;">$this-&gt;privateKey</span> &quot;</span><span style="color: #339933;">.</span>
                <span style="color: #0000ff;">&quot;-outform der -nodetach -binary| <span style="color: #006699; font-weight: bold;">$this-&gt;pathOpenSSL</span> smime -encrypt &quot;</span><span style="color: #339933;">.</span>
                <span style="color: #0000ff;">&quot;-des3 -binary -outform pem <span style="color: #006699; font-weight: bold;">$this-&gt;paypalKey</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$descriptors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pipe&quot;</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>
            <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pipe&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$process</span> <span style="color: #339933;">=</span> <span style="color: #990000;">proc_open</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$openssl_cmd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$descriptors</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pipes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_resource</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$process</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$key</span>=<span style="color: #006699; font-weight: bold;">$value</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fflush</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pipes</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$return_value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">proc_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$process</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ERROR: encryption failed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setOpenSSLPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OpenSSLPath &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; don\'t exists'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pathOpenSSL</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$path</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Cette classe est au final assez simple, elle permet de définir les certificats à utiliser, d&#8217;insérer des valeurs avec la méthode addData (Suivant la <a title="Documentation Paypal" href="https://www.paypal-france.fr/webscr/fr_FR/html/Espace-Integration-PayPal/ic_std-variable-reference.html" target="_blank">documentation Paypal</a> pour les paramètres possibles) et de générer la chaîne cryptée via la méthode getCryptedData. Quelques informations sont prédéfinies dans la propriété $data de l&#8217;objet, se sont celles qui ne varient pas. Par défaut le chemin vers l&#8217;exécutable OpenSSL sur le serveur est /usr/bin/openssl (valable sous Debian), cette valeur peut être modifiée dans le constructeur de l&#8217;objet.</p>
<p>Voici donc un exemple d&#8217;utilisation pour la vente d&#8217;un objet &laquo;&nbsp;Boite à meuh&nbsp;&raquo; au prix de 10€ sur le compte Paypal &laquo;&nbsp;toto@toto.com&nbsp;&raquo; :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/chemin/vers/PaypalCrypt.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Initialisation cryptage Paypal</span>
<span style="color: #000088;">$paypalCrypt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PaypalCrypt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$paypalCrypt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPrivateKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/chemin/vers/clepriv.pem'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$paypalCrypt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPublicKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/chemin/vers/certpub.pem'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$paypalCrypt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPaypalKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/chemin/vers/cert/paypal_cert.pem'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$paypalCrypt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cert_id'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'id_certificat_fourni_par_paypal'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'business'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'toto@toto.com'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'no_note'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shipping'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tax'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rm'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'2'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cbt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Retour sur la boutique'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'id_membre'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'return'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://mon_site.com/return.php'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cancel_return'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://mon_site.com/cancel.php'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notify_url'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://mon_site.com/ipn.php'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'amount'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item_name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Boite à meuh'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item_number'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'identifiant_produit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$paypalCrypt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCryptedData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=&quot;https://www.paypal.com/fr/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_s-xclick&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;encrypted&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$data</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
    &lt;input type=&quot;submit&quot; value=&quot;Commander&quot; class=&quot;input_button&quot;&gt;
&lt;/form&gt;</pre></div></div>

<p>Pour l&#8217;information <strong>cert_id </strong>il faut bien entendu fournir la valeur que Paypal vous a donné à l&#8217;étape 2 (Oui oui j&#8217;ai écrit qu&#8217;il fallait le noter <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<p>Et voilà vous avez un joli bouton Paypal crypté en SSL pour faire vos demandes de paiement. Pour connaître toutes les valeurs possibles que vous pouvez ajouter je vous laisse regarder la <a title="Documentation Paypal" href="https://www.paypal-france.fr/webscr/fr_FR/html/Espace-Integration-PayPal/ic_std-variable-reference.html" target="_blank">documentation Paypal.</a> N&#8217;oubliez pas non plus que cela ne vous dispense pas de faire toutes les vérifications nécessaires lors du feedback de Paypal (IPN) pour vérifier la cohérence entre la commande passée chez vous et le paiement que vous avez reçu.</p>
<p><strong>MAJ 30/08/2011:</strong> Changement de méthode pour l&#8217;appel à OpenSSL pour maximiser la compatibilité avec les différentes plateformes (Windows).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2011/08/30/creer-dynamiquement-un-bouton-paypal-securise/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Algorithme: Changement de base d&#8217;un nombre</title>
		<link>http://www.exinsidephp.com/2011/05/24/algorithme-changement-de-base-dun-nombre/</link>
		<comments>http://www.exinsidephp.com/2011/05/24/algorithme-changement-de-base-dun-nombre/#comments</comments>
		<pubDate>Tue, 24 May 2011 11:41:30 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[PHP5/POO]]></category>
		<category><![CDATA[algorithme]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[base_encode]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=533</guid>
		<description><![CDATA[Un article sur le blog ! Hé oui ça faisait longtemps&#8230; preuve du début de la fin du commencement ! Bon tout ça pour dire que j&#8217;ai libéré du temps pour mes projets personnels et que cela va bouger ici et là. Cet intermède étant terminé, revenons au sujet de cet article. Il existe plusieurs fonctions intégrées]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2011/05/conversion-hexadecimal-binaire.gif"><img class="alignleft size-full wp-image-534" title="conversion-hexadecimal-binaire" src="http://www.exinsidephp.com/wp-content/uploads/2011/05/conversion-hexadecimal-binaire.gif" alt="" width="265" height="185" /></a>Un article sur le blog ! Hé oui ça faisait longtemps&#8230; preuve du début de la fin du commencement ! Bon tout ça pour dire que j&#8217;ai libéré du temps pour mes projets personnels et que cela va bouger ici et là. Cet intermède étant terminé, revenons au sujet de cet article.</p>
<p>Il existe plusieurs fonctions intégrées à PHP permettant de passer un nombre d&#8217;une base à une autre, la plus généraliste étant <a title="Documentation Base Convert" href="http://fr.php.net/base_convert" target="_blank">base_convert</a>. Vous me direz que cette fonction suffit dans la plupart des cas, oui mais le problème c&#8217;est qu&#8217;on ne peut dépasser la base 36&#8230; On va donc faire un petit rappel de ce qu&#8217;est une base, et expliciter pourquoi on peut avoir besoin de base &laquo;&nbsp;personnalisée&nbsp;&raquo; supérieur à 36.</p>
<p><span id="more-533"></span><strong>Qu&#8217;est ce qu&#8217;une base ?</strong></p>
<p>Une base permet de représenter un nombre et il y en a une que l&#8217;on utilise tous les jours : La base 10. Dans la base 10 c&#8217;est simple, chaque chiffre représente lui même c&#8217;est la base permettant de faire le plus facilement des calculs sur des nombres (du point de vue de l&#8217;humain, pas de celui de la machine <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Pour être un peu verbeux un nombre en base 10 est un somme de puissance de 10.  En changeant de base, nous changeons la représentation de ce nombre mais pas sa valeur. Alors pourquoi on se torture l&#8217;esprit à vouloir représenter un nombre dans d&#8217;autres bases ? La première raison est l&#8217;informatique ! car une machine ne comprends pas les nombres tel que nous les assimilons en base 10. C&#8217;est pour cela que ce nombre est représenté en base 2 pour que la machine puisse faire des calculs sur celui-ci car elle ne sait faire qu&#8217;une seule chose : Ouvrir ou fermer des circuits électriques soit 1 ou 0. Voilà pour la petite histoire, maintenant vous allez me dire, pourquoi vouloir représenter un nombre dans une base plus grande que la base 10 ? Pour réduire la taille de la représentation de ce nombre pardi ! En effet, plus votre base est élevée et moins il vous faudra de symboles pour représenter un même nombre. On parle en effet de &laquo;&nbsp;symbole&nbsp;&raquo; car au dessus de la base 10 les puissances vont être représentées par un symbole, soit des lettres et bien plus encore.</p>
<p>Donc, lorsque l&#8217;on veut réduire au maximum la représentation d&#8217;un nombre une base 36 c&#8217;est un peu limitant dès que l&#8217;un atteint des nombres assez grands. Par exemple, 1 milliard en base 36 s&#8217;écrit GJDGXS soit 6 caractères au lieu de 10 en base 10&#8230; peut mieux faire !</p>
<p><strong>Algorithme de changement de base personnalisé</strong></p>
<p>Voici donc une classe PHP5 avec l&#8217;algorithme vous permettant de convertir un nombre d&#8217;une base x à une base y. Elle permet, avec sa configuration de base, de convertir un nombre de la base 2 à la base 64, mais vous pouvez aller aussi loin que vous le souhaitez en ajoutant autant de caractères que vous le voulez pour créer des bases de plus en plus grandes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BaseConverter <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$baseChars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$maxBase</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Construct with a specified base or not
     * @param Array $base
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseChars</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$base</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">else</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseChars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'z'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseChars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Convert a number from a base to an another base
     * @param mixed $number The representation of the number on the current base
     * @param int $fromBase The base of the number to convert (10 by default)
     * @param int $toBase The base to convert the number
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> convert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fromBase</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$toBase</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$toBase</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Min value of toBase are 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromBase</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Min value of fromBase are 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$toBase</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Max value of toBase are '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromBase</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Max value of fromBase are '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$number</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$toBase</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">convertToBase10</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fromBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fromBase</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">convertToBase10</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fromBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$datas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseChars</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$toBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Calculate value</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$toBase</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$number</span><span style="color: #339933;">%</span><span style="color: #000088;">$toBase</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number</span><span style="color: #339933;">/</span><span style="color: #000088;">$toBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$number</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Convert a representation of a number to base 10
     * @param string $characters The number to convert
     * @param int $base The base of the number, by default 64
     * @return int
     */</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> convertToBase10<span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #339933;">,</span> <span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">64</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Min value of base are 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Max value of base are '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">maxBase</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$powBase</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$p</span><span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000088;">$char</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$char</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$number</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">array_search</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$char</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseChars</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$powBase</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$powBase</span> <span style="color: #339933;">*=</span> <span style="color: #000088;">$base</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$number</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Voilà pour l’algorithme de base, et un exemple d&#8217;utilisation :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$conv</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BaseConverter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$conv</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">convert</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1000000000</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Affichera GJDGXS</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Voilà avec ceci vous pouvez développer un <strong>raccourcisseur d&#8217;urls</strong> (Pour ceux qui n&#8217;avaient pas encore saisi l&#8217;astuce pour ce type de service <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) ou encore masquer (de façon basique mais c&#8217;est mieux que rien) les identifiants numérique que l&#8217;on passe parfois dans les URL&#8230; Les applicatifs ne manquent pas, je laisse donc libre cours à votre imagination !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2011/05/24/algorithme-changement-de-base-dun-nombre/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EXinsidePHP &#8211; Rétrospective 2010</title>
		<link>http://www.exinsidephp.com/2010/12/30/exinsidephp-retrospective-2010/</link>
		<comments>http://www.exinsidephp.com/2010/12/30/exinsidephp-retrospective-2010/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 13:33:36 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Divers]]></category>
		<category><![CDATA[Auto-Entrepreneur]]></category>
		<category><![CDATA[Développeur Web]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Lille]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Paris]]></category>
		<category><![CDATA[Rétrospective]]></category>
		<category><![CDATA[Valenciennes]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=495</guid>
		<description><![CDATA[C&#8217;est bien la première fois que je vais m&#8217;exercer à ce petit exercice de la rétrospective, il faut dire que 2010 aura été une année pendant laquelle il s&#8217;est vraiment passé beaucoup de choses sur plusieurs plans. Dans cette rétrospective je vais retracer quelques éléments professionnels et personnels, au final tout ne sera pas forcément]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/12/retro.jpg"><img class="size-medium wp-image-496 alignleft" title="Rétrospective 2010" src="http://www.exinsidephp.com/wp-content/uploads/2010/12/retro-300x207.jpg" alt="" width="240" height="172" /></a>C&#8217;est bien la première fois que je vais m&#8217;exercer à ce petit exercice de la rétrospective, il faut dire que 2010 aura été une année pendant laquelle il s&#8217;est vraiment passé beaucoup de choses sur plusieurs plans. Dans cette rétrospective je vais retracer quelques éléments professionnels et personnels, au final tout ne sera pas forcément intéressant avec quelques contenus assez inhabituels sur ce blog (vous êtes prévenu)&#8230; Allé on démarre, et je remercie d&#8217;avance les quelques personnes qui trouveront le courage de lire cet article <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h4><span id="more-495"></span><strong>Démission, Auto-Entrepreneur, Nouvel employeur&#8230; Surbooking !<br />
</strong></h4>
<p>Cela résume un peu la situation du point de vu professionnel, mouvementé&#8230; Fin décembre de l&#8217;année dernière, et après 2 ans et demie de bons et loyaux services je décide de quitter mon précédent employeur (<a href="http://www.pubeco.fr">Pubeco</a>) pour voir d&#8217;autres horizons. Après plusieurs entretiens dans quelques boites assez connues dans le web (Pixmania, Twenga, Oxygem etc) je décide de signer pour un poste à Paris 2ième chez Maximiles dans le pôle R&amp;D. Je devais commencer mi-janvier, branle bas de combat, je déménage quelques affaires chez un ami qui m&#8217;héberge pour commencer, en laissant un peu sous le choque ma moitié&#8230; Je suis resté quelques jours pour découvrir un peu <strong>Paris</strong> afin de tenter de m&#8217;acclimater à cette &laquo;&nbsp;ville&nbsp;&raquo;. Au final j&#8217;ai fait volte face la veille de commencer, décidément la province me manquait trop. De retour à Valenciennes je commence à faire jouer quelques contacts puisque j&#8217;avais prévu un peu le coup en créant mon statut d&#8217;auto-entrepreneur à partir du 1er Janvier 2010. J&#8217;ai donc pu bricoler un peu les trois premiers mois, avant qu&#8217;une entreprise Lilloise me rappelle pour savoir si mon travail à Paris me convenait. J&#8217;explique la situation, et donc entretient le lendemain, on m&#8217;expose le nouveau projet de l&#8217;entreprise, projet qui me plait. Deuxième appel le lendemain pour confirmer mon embauche et démarrage le 1er Mars (Oui cela a été plutôt rapide). En parallèle je garde mon statut d&#8217;auto-entrepreneur me permettant de faire quelques prestations, en travaillant beaucoup avec une agence parisienne (<a href="http://www.celaneo.com/" target="_blank">Celaneo</a>), en fait c&#8217;est mon plus gros client sur cette année 2010.</p>
<h4>Les projets EXinsidePHP</h4>
<p>Du côtés de ce site cela a beaucoup bougé à vrai dire. La première résolution a été de me re-concentrer sur ce que je savais faire, et ce que je pouvais faire sur ce site. J&#8217;ai donc décidé de passer d&#8217;un site fait à main, avec pas mal de choses inutiles, à un blog pour recentrer ce site sur l&#8217;information et des choses qui apportent vraiment quelque chose. Aujourd&#8217;hui EXinsidePHP est un blog ou je partage des informations liées aux web, au développement suite à mes diverses expériences en espérant que cela soit utile pour quelques personnes. Mais ce n&#8217;est pas tout, je n&#8217;ai pas pour autant oublié l&#8217;aspect <strong>Open Source</strong> qui a fait ce que je suis aujourd&#8217;hui. Il y avait 2 projets, un premier qui est <a href="http://www.exinsidephp.com/exmail/">EXmail</a>, qui malgré le poids des années est toujours relativement utilisé et semble utile à pas mal de personnes (Même s&#8217;il y a bien des choses à revoir dessus). Il reste tout de même un mini-projet secondaire, pour l&#8217;instant je le maintiens en vie&#8230; Le deuxième projet existant était <strong>EXlor</strong>, une application de livre d&#8217;or&#8230; J&#8217;avais commencé une réécriture mais elle s&#8217;est un peu enlisée, tout comme l&#8217;intérêt aujourd&#8217;hui pour les livres d&#8217;or&#8230; De ce fait, je l&#8217;ai abandonné, il n&#8217;avait plus vraiment de raison d&#8217;être ! Il y avait enfin un pseudo troisième projet, un peu &laquo;&nbsp;bâtard&nbsp;&raquo;, qui est <a href="http://www.exinsidephp.com/exframework/">ExFramework</a>. Alors lui il est né un peu n&#8217;importe comment, il a traversé les années en s&#8217;étoffant en le définissant vulgairement &laquo;&nbsp;framework&nbsp;&raquo;, c&#8217;était plus, dans sa première version, un ensemble de tout et de rien sans réelle cohérence. A partir de là je me suis dit on va repartir de zéro, &laquo;&nbsp;from scratch&nbsp;&raquo; comme on dit, avec un réel objectif de faire un Framework correspondant à ma vision de certaines choses, me permettant avant tout de faire mes petits projets avec mes petits outils que je maitrise. La <a href="http://www.exinsidephp.com/exframework/">version 2</a> est donc actuellement en plein chantier sans prétention aucune, et je n&#8217;affirmerais pas qu&#8217;il est parfait, rien n&#8217;est parfait <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Au final si ce projet est suivi par la suite tant mieux, sinon tant pis, il me servira à moi ne vous inquiétez pas. J&#8217;ai d&#8217;ailleurs mis en place un <a href="http://tracker.exinsidephp.com/">tracker</a> et un <a href="http://websvn.exinsidephp.com/wsvn/ExFramework">websvn</a> me permettant d&#8217;organiser cela un peu mieux (Tout n&#8217;est pas encore totalement configuré, j&#8217;ai déjà eu bien du mal à trouver des outils corrects&#8230;). Aujourd&#8217;hui je me concentre surtout sur ExFramework, et j&#8217;ai malheureusement assez peu de temps pour faire des articles sur le blog mais quand j&#8217;ai un petit moment j&#8217;essaye de le faire.</p>
<h4>OpenMailing</h4>
<p>Hé oui, même si je n&#8217;en parle pas (comme beaucoup de choses en fait), ce projet est très loin d&#8217;être abandonné, il murie, il s&#8217;affine. C&#8217;est un projet auquel je tiens beaucoup et auquel j&#8217;y crois beaucoup aussi quant à son potentiel. Quelques personnes me suivent à ce niveau, beaucoup de discutions&#8230; Au final un business plan a été rédigé (Il va sans doute être un peu révisé) afin d&#8217;avoir les idées claires, de bien définir les tenants et les aboutissants. Qui dit business plan, dit recherche de financement. Nous avançons donc de ce côté, avec un peu de chance cette aventure démarrera officiellement l&#8217;année prochaine, comme quoi en 2011 ça risque de bouger aussi ! D&#8217;ailleurs si vous avez quelques pécules et que vous ne savez qu&#8217;en faire, dites le moi :p J&#8217;en dirais plus le moment venu&#8230;</p>
<h4>Personnel</h4>
<p>Ça c&#8217;est le moment que vous allez adorer en racontant un peu ma vie, je vais être assez bref quand même. Il y a eu des bas, mais beaucoup de haut quand même. Cette année j&#8217;ai découvert que je n&#8217;étais pas issu de la divine fécondation et que j&#8217;avais ce que vous appelez &laquo;&nbsp;un père&nbsp;&raquo;. Au final je l&#8217;ai vu une fois (de trop ?), c&#8217;est déjà pas mal&#8230; Un peu plus réjouissant, nous avons fêté avec ma moitié notre première bougie ensemble, en cadeau nous avons emménagé ensemble dans un appartement à <strong>Valenciennes</strong>. Et comme j&#8217;aime faire les choses en grand, on s&#8217;est dit qu&#8217;à noël il fallait marquer le coup, nous avons donc acheté une maison en VEFA, à Valenciennes toujours et bien entendu. L&#8217;offre de prêt vient d&#8217;être renvoyée, elle sera livrée courant janvier si tout va bien. Sinon à part ça&#8230; Ha si, mon chat vient de se faire castrer <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Conclusion</h4>
<p>2010 a été un excellent cru, sur tous les niveaux, et vu comme c&#8217;est parti&#8230; En 2011 cela risque d&#8217;être encore plus mouvementé ! Allé je vous souhaite à tous un bon réveillon de fin d&#8217;année 2010, mais avec modération bien entendu&#8230; Ou pas !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/12/30/exinsidephp-retrospective-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mettre en page un bouton d&#8217;upload</title>
		<link>http://www.exinsidephp.com/2010/12/04/mettre-en-page-un-bouton-dupload/</link>
		<comments>http://www.exinsidephp.com/2010/12/04/mettre-en-page-un-bouton-dupload/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 14:18:49 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Xhtml/CSS]]></category>
		<category><![CDATA[astuce]]></category>
		<category><![CDATA[input file]]></category>
		<category><![CDATA[Intégration]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[upload]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=477</guid>
		<description><![CDATA[L&#8217;élément html input file est sans doute le plus difficile à mettre en forme, en fait (hors HTML5) c&#8217;est tout simplement impossible avec seulement des feuilles de style. Une alternative, dans certains cas, est de faire un upload progressif avec Flash mais dans ce cadre nous n&#8217;avons plus à proprement parler de champ d&#8217;upload de]]></description>
			<content:encoded><![CDATA[<div id="attachment_478" class="wp-caption alignleft" style="width: 310px"><a href="http://www.exinsidephp.com/wp-content/uploads/2010/12/btn_upload.png"><img class="size-medium wp-image-478" title="btn_upload" src="http://www.exinsidephp.com/wp-content/uploads/2010/12/btn_upload-300x206.png" alt="" width="300" height="206" /></a><p class="wp-caption-text">Les boutons d&#39;upload sur les différents navigateurs...</p></div>
<p>L&#8217;élément html <strong>input file</strong> est sans doute le plus difficile à mettre en forme, en fait (hors <strong>HTML5</strong>) c&#8217;est tout simplement impossible avec seulement des feuilles de style. Une alternative, dans certains cas, est de faire un upload progressif avec <strong>Flash</strong> mais dans ce cadre nous n&#8217;avons plus à proprement parler de champ d&#8217;upload de fichier dans le formulaire&#8230;</p>
<p>Pourtant il existe bel et bien une solution, avec un peu d&#8217;astuce et de javascript (dans ce tutoriel avec <strong>Jquery</strong>) je vais vous montrer comment mettre en page cet élément html afin d&#8217;avoir une intégration cohérente et identique avec tous les navigateurs (et c&#8217;est même compatible avec <strong>Internet Explorer 6</strong> !).</p>
<p><span id="more-477"></span></p>
<p>Tout d&#8217;abord il nous faut un objectif, qui sera par exemple l&#8217;objectif graphique dicté par le psd du graphiste, dans ce tutoriel nous voulons donc que le bouton d&#8217;upload soit comme ceci sur tous les navigateurs :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/12/upload_objectif.png"><img class="aligncenter size-medium wp-image-482" title="Mise en page bouton d'upload" src="http://www.exinsidephp.com/wp-content/uploads/2010/12/upload_objectif-300x61.png" alt="" width="300" height="61" /></a>Et voici la liste des navigateurs avec lesquels nous voulons que cela fonctionne :</p>
<ul>
<li>Internet Explorer 6,7,8</li>
<li>Firefox 2,3</li>
<li>Google Chrome</li>
<li>Opera 10</li>
<li>Safari</li>
</ul>
<p>Soit une belle petite collection qui peut faire peur au premier abord&#8230; Commençons par l&#8217;aspect théorique, nous allons déjà définir des styles pour mettre en page individuellement un input text et un bouton, ce qui donne assez simplement ceci en CSS :</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.fakefile</span> input.input_background<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/input.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">7px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    _padding<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">9px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">252px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">medium</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.fakefile</span> input.input_button<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/upload.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">88px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">medium</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Maintenant que c&#8217;est fait, comment appliquer cela au champ d&#8217;upload ? En fait nous allons leurrer un peu les navigateurs en jouant notamment sur le z-index. L&#8217;idée est ici d&#8217;afficher réellement un input text, un bouton juste à coté, et d&#8217;avoir le champ d&#8217;upload &laquo;&nbsp;par dessus&nbsp;&raquo; en invisible permettant de garder l&#8217;événement de sélection du fichier en jouant sur les z-index. En HTML et CSS pure cela donne quelque chose comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Sélectionner le fichier à envoyer :<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fileinputs&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fakefile&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input_background&quot;</span> <span style="color: #000066;">readonly</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;readonly&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;input_button&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Et la feuille de style correspondante :</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.fileinputs</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">350px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.fileinputs</span> input<span style="color: #6666ff;">.file</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    _margin-<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">350px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.fileinputs</span> input<span style="color: #6666ff;">.file</span>.<span style="color: #993333;">hidden</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
    -moz-opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #00AA00;">;</span>
    filter<span style="color: #00AA00;">:</span>alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.fakefile</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">370px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">90%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.fakefile</span> input <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
div<span style="color: #6666ff;">.fakefile</span> input.input_background<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/input.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">7px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    _padding<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">9px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">3px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">252px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">medium</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.fakefile</span> input.input_button<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/upload.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">88px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">medium</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Avec ce code nous avons <strong>presque</strong> ce que nous souhaitons, la mise en page est conforme et lorsque l&#8217;on clique sur le bouton la fenêtre de sélection de fichier s&#8217;ouvre. Par contre lorsque l&#8217;on sélectionne un fichier, le champ texte ne se rempli pas avec le nom du fichier sélectionné. C&#8217;est normal, c&#8217;est le champ input file qui reçoit cette information et comme il est invisible&#8230; Rien ne s&#8217;affiche. C&#8217;est ici que <strong>Javascript</strong> va intervenir, nous allons &laquo;&nbsp;binder&nbsp;&raquo; l&#8217;événement <strong>onChange</strong> et lors de celui-ci nous allons mettre la valeur du champ input file, dans le champ input text. Nous allons en profiter pour alléger le code HTML en générant la partie &laquo;&nbsp;mise en page&nbsp;&raquo; avec le Javascript.</p>
<p>Pour le code HTML simplifié cela donne ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Sélectionner le fichier à envoyer :<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fileinputs&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Et voici le code javascript avec <strong>Jquery</strong> :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> initFileUploads<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=file]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fakefile'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input/&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'type'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'readonly'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input_background'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input/&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'type'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'button'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input_button'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hidden'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=file]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=text]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    initFileUploads<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pour le code CSS cela sera le même que précédemment, voilà c&#8217;est terminé. Nous avons rempli notre objectif initial sans remettre en cause l&#8217;intégration HTML &laquo;&nbsp;classique&nbsp;&raquo;, tout en ayant une solution graphique uniforme avec tous les navigateurs et ceci sans dégrader la fonction initiale du bouton d&#8217;upload.</p>
<p>Vous pouvez tester l&#8217;exemple complet sur cette page : <a title="Tutorial mise en page bouton d'upload" href="http://www.exinsidephp.com/tutorial/tuto_upload/" target="_blank">Exemple intégration bouton d&#8217;upload</a></p>
<p>Et vous pouvez télécharger celui-ci ici : <p style="text-align:center"><a href="http://www.exinsidephp.com/wp-content/plugins/download-monitor/download.php?id=5" title="Télécharger Exemple intégration bouton d’upload"><img src="http://www.exinsidephp.com/wp-content/plugins/download-monitor/img/download.gif" alt="Exemple intégration bouton d’upload"/></a></p>
<p style="text-align:center"><a href="http://www.exinsidephp.com/wp-content/plugins/download-monitor/download.php?id=5" title="Télécharger Exemple intégration bouton d’upload"><strong>Exemple intégration bouton d’upload </strong> <br/><img alt="zip" title="zip" class="download-icon" src="http://www.exinsidephp.com/wp-content/plugins/download-monitor/img/filetype_icons/document-zipper.png" /> Téléchargé 408 fois</a></p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/12/04/mettre-en-page-un-bouton-dupload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mise à jour: ExMail 2 Beta 3</title>
		<link>http://www.exinsidephp.com/2010/12/02/mise-a-jour-exmail-2-beta-3/</link>
		<comments>http://www.exinsidephp.com/2010/12/02/mise-a-jour-exmail-2-beta-3/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 11:00:42 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Les projets EXinsidePHP]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=474</guid>
		<description><![CDATA[Une petite mise à jour d&#8217;Exmail suite à quelques bugs reportés récemment par mail. Version BETA 3 : - Ajout PHPDocs sur les méthodes de la class Exmail - Modification de la méthode de validation des emails - Modification de la méthode isEmpty - Ajout de la méthode cleanMagicQuote permettant la compatibilité avec les serveurs]]></description>
			<content:encoded><![CDATA[<p>Une petite mise à jour d&#8217;Exmail suite à quelques bugs reportés récemment par mail.</p>
<p><strong>Version BETA 3 :</strong></p>
<p>- Ajout PHPDocs sur les méthodes de la class Exmail<br />
- Modification de la méthode de validation des emails<br />
- Modification de la méthode isEmpty<br />
- Ajout de la méthode cleanMagicQuote permettant la compatibilité avec les serveurs avec les magic_quotes activées<br />
- Compatibilité (suppression Warning) avec PHP 5.3</p>
<p style="text-align: center;"><a href="../exmail/">Téléchargement d&#8217;EXmail</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/12/02/mise-a-jour-exmail-2-beta-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outils pour Webmasters se met à jour&#8230; Variantes des Mots-Clés</title>
		<link>http://www.exinsidephp.com/2010/09/06/outils-pour-webmasters-se-met-a-jour-variantes-des-mots-cles/</link>
		<comments>http://www.exinsidephp.com/2010/09/06/outils-pour-webmasters-se-met-a-jour-variantes-des-mots-cles/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 08:25:52 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[SEO/Référencement]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Webmaster Tools]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=459</guid>
		<description><![CDATA[Webmaster Tools, pour les intimes, a subit une petite mise à jour, à la limite du visible il faut bien l&#8217;avouer&#8230; Mais une mise à jour plutôt intéressante dont je me suis rendu compte aujourd&#8217;hui. Elle se situe dans Votre site sur le Web, puis Mots clés. Vous voyez ? Non ? Regardez bien votre]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/09/ggwmt.png"><img class="size-full wp-image-460 alignleft" title="Mots clés, Google Webmaster Tools" src="http://www.exinsidephp.com/wp-content/uploads/2010/09/ggwmt.png" alt="" width="347" height="256" /></a></p>
<p>Webmaster Tools, pour les intimes, a subit une petite mise à jour, à la limite du visible il faut bien l&#8217;avouer&#8230; Mais une mise à jour plutôt intéressante dont je me suis rendu compte aujourd&#8217;hui. Elle se situe dans <strong>Votre site sur le Web</strong>, puis <strong>Mots clés</strong>. Vous voyez ? Non ? Regardez bien votre liste de mots clés&#8230; Désormais Google vous donne les mots clés et leurs variantes qu&#8217;il a reconnu sur votre site et les rassemble. L&#8217;information qui est intéressante (mais que l&#8217;on savait déjà) c&#8217;est que Google rassemble en fait les mots sous des groupes incluant des variantes. Mais surtout on peut vérifier qu&#8217;il a bien reconnu et rassembler certains mots clés sur votre site, intéressant pour suivre notre référencement une fois de plus.</p>
<p>Voilà c&#8217;était le micro-article du jour <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/09/ggwmt.png"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/09/06/outils-pour-webmasters-se-met-a-jour-variantes-des-mots-cles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimisation : Les POSIX (ereg) et les PCRE (preg)</title>
		<link>http://www.exinsidephp.com/2010/07/02/optimisation-les-posix-ereg-et-les-pcre-preg/</link>
		<comments>http://www.exinsidephp.com/2010/07/02/optimisation-les-posix-ereg-et-les-pcre-preg/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 13:00:00 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Optimisation]]></category>
		<category><![CDATA[PHP5/POO]]></category>
		<category><![CDATA[ereg]]></category>
		<category><![CDATA[pcre]]></category>
		<category><![CDATA[posix]]></category>
		<category><![CDATA[preg]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=9</guid>
		<description><![CDATA[<p>Derrière ces deux noms barbares, les POSIX et les PCRE, se cache deux libraires d'expressions rationnelles. Pour être plus parlant, lorsque vous utilisez les fonctions "ereg" vous utilisez la librairie POSIX et lorsque vous utilisez les fonctions "preg" vous utilisez la librairie PCRE. A noter tout de même que les deux librairies (et donc les fonctions associées) permettent de faire exactement les mêmes choses. Comme vous pouvez le remarquer sur la documentation officielle de PHP vous trouverez ce genre de mention lorsque vous consultez la documentation des fonctions ereg :<blockquote><p><strong class="note">Note</strong>: <a href="http://fr.php.net/manual/fr/function.preg-match.php" class="function">preg_match()</a>, qui utilise la syntaxe des expressions rationnelles compatibles PERL, est une alternative plus rapide de <strong>ereg()</strong></p> </blockquote>Notez aussi que vous avez désormais cette mention qui apparait :</p> <blockquote><p><br />Cette fonction est <em class="emphasis">OBSOLETE</em> depuis PHP 5.3.0 et a été <em class="emphasis">SUPPRIMEE</em> depuis PHP 6.0.0. Nous vous encourageons vivement à ne plus l'utiliser.</p> </blockquote> <p>Alors pourquoi l'utilisation des POSIX est déconseillée, pourquoi depuis PHP 5.3 elles sont devenues obsolètes et enfin pourquoi elles vont être supprimée dans PHP 6 ? La réponse dans la suite de cette article...</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/08/iStock_000006432173XSmall.jpg"><img class="size-medium wp-image-269 alignright" title="Optimisation" src="http://www.exinsidephp.com/wp-content/uploads/2010/08/iStock_000006432173XSmall-300x299.jpg" alt="Optimisation" width="163" height="163" /></a>Derrière ces deux noms barbares, les POSIX et les PCRE, se cache deux librairies d&#8217;expressions rationnelles. Pour être plus parlant, lorsque vous utilisez les fonctions &laquo;&nbsp;ereg&nbsp;&raquo; vous utilisez la librairie POSIX et lorsque vous utilisez les fonctions &laquo;&nbsp;preg&nbsp;&raquo; vous utilisez la librairie PCRE. A noter tout de même que les deux librairies (et donc les fonctions associées) permettent de faire exactement les mêmes choses. <span id="more-9"></span></p>
<p>Comme vous pouvez le remarquer sur la documentation officielle de PHP vous trouverez ce genre de mention lorsque vous consultez la documentation des fonctions ereg :</p>
<blockquote><p><strong class="note">Note</strong>: <a class="function" href="http://fr.php.net/manual/fr/function.preg-match.php">preg_match()</a>, qui utilise la syntaxe des expressions rationnelles compatibles PERL, est une alternative plus rapide de <strong>ereg()</strong></p></blockquote>
<p>Notez aussi que vous avez désormais cette mention qui apparait :</p>
<blockquote><p>Cette fonction est <em class="emphasis">OBSOLETE</em> depuis PHP 5.3.0 et a été <em class="emphasis">SUPPRIMEE</em> depuis PHP 6.0.0. Nous vous encourageons vivement à ne plus l&#8217;utiliser.</p></blockquote>
<p>Alors pourquoi l&#8217;utilisation des POSIX est déconseillée, pourquoi depuis PHP 5.3 elles sont devenues obsolètes et enfin pourquoi elles vont être supprimée dans PHP 6 ? La réponse dans la suite de cette article&#8230;</p>
<p><!--more--></p>
<p>Pour faire ce test de performance, on va utiliser le même protocole de test que dans <a href="http://www.exinsidephp.com/2009/01/27/optimisation-la-concatenation2/">l&#8217;article sur la concaténation</a>. Nous allons utiliser sur ce petit test la validation d&#8217;une adresse email. Nous étudierons deux cas, le cas ou l&#8217;adresse email est bonne et le cas ou elle ne l&#8217;est pas. Nous baserons nos tests sur 100 000 itérations pour révéler clairement les différences de performance. Les regex dans les tests seront tirés du très bon site <a title="Expreg" href="http://www.expreg.com/lire-mail-source" target="_blank">Expreg</a>.</p>
<ul>
<li><strong>Cas avec une adresse email correcte</strong></li>
</ul>
<p>Voici le code que nous allons utiliser pour ce premier test, avec la fonction <a title="Documentation Ereg" href="http://fr.php.net/ereg" target="_blank">ereg</a> (POSIX):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Benchmark.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'info@e-ur-ope.a.n-cards.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">ereg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;^[[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-.]?[[:alnum:]])*\.([a-z]{2,4})$&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStats</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' secondes'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Et voici celui pour <a title="Documentation preg_match" href="http://fr.php.net/preg_match" target="_blank">preg_match</a> (PCRE):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Benchmark.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'info@e-ur-ope.a.n-cards.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'`^[[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-.]?[[:alnum:]])*\.([a-z]{2,4})$`'</span><span style="color: #339933;">,</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStats</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' secondes'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Voici les résultats dans un graphique :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_1.png"><img class="aligncenter size-full wp-image-439" title="Performance PCRE vs POSIX" src="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_1.png" alt="" width="300" height="250" /></a></p>
<p>On se rend compte que la fonction ereg est ainsi <strong>38% plus lente</strong> que la fonction preg_match sur ce simple test, un écart de performance qui est tout de même assez conséquent et qui commence à confirmer le choix de la team PHP de vouloir supprimer les fonctions POSIX&#8230;</p>
<ul>
<li><strong>Cas avec une adresse email incorrecte</strong></li>
</ul>
<p>Nous allons maintenant faire les mêmes tests avec une chaîne invalide qui est :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'info@e-ur-ope.a.n-cards .com'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Voici les résultats :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_2.png"><img class="aligncenter size-full wp-image-440" title="Performance POSIX vs PCRE" src="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_2.png" alt="" width="300" height="250" /></a>On constate ainsi plusieurs choses avec ce graphique, la première c&#8217;est que pour l&#8217;une ou l&#8217;autre des fonctions le temps de réponse est plus court que lors du premier test, ce qui est normal par rapport au fonctionnement d&#8217;une expression régulière. Deuxième observation, on  remarque que l&#8217;écart de performance est pour ainsi dire identique (37%) que lors du premier test, mais est ce que cet écart est toujours le même avec une chaîne plus longue ? C&#8217;est ce que nous allons voir  :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'une_tr_longu_adresse_email_qui_est_interminable_info@e-ur-ope.a.n-cards .com'</span><span style="color: #339933;">;</span></pre></div></div>

<p>Et voici le résultat :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_3.png"><img class="aligncenter size-full wp-image-441" title="Performance POSIX vs PCRE" src="http://www.exinsidephp.com/wp-content/uploads/2010/08/test_3.png" alt="" width="300" height="250" /></a>Vous le voyez vous même&#8230; L&#8217;écart de performance commence sérieusement à grimper, la fonction ereg est ainsi <strong>73% plus lente</strong> que la fonction preg_match, échec et mat !</p>
<p><strong>En conclusion</strong> de ce bref test (est-il utile d&#8217;en faire plus ?) on remarque bien l&#8217;écart important de performance entre les POSIX et les PCRE qui devient d&#8217;autant plus important lorsque l&#8217;on travaille sur de longues chaînes de caractères mais aussi en fonction de la complexité du masque. L&#8217;utilisation des POSIX est donc <strong>à bannir de vos scripts</strong> et personne ne regrettera le choix de PHP de&#8230; L&#8217;abandonner !</p>
<p>Pour aller plus loin les expressions régulières sont des fonctions lourdes et je ne saurais trop vous conseiller de ne les utiliser que lorsque vous en avez réellement besoin (cf le bonus ci-dessous).</p>
<p><strong>Bonus: Pour aller plus loin&#8230;<br />
</strong></p>
<p>Imaginons que vous voulez détecter la présence d&#8217;un mot dans une chaîne de caractéres, je remarque souvent que beaucoup utilisent une expression régulière plutôt que <a title="Documentation strpos" href="http://fr.php.net/strpos" target="_blank">strpos</a><strong>.</strong> J&#8217;ai toujours été partisan d&#8217;utiliser strpos dans ce cas de figure car je pense qu&#8217;une fonction native dédiée à ce que l&#8217;on veut est plus rapide&#8230; Voici donc un petit test avec preg_match :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Benchmark.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Check this string for finding a GoogleBot !'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">300000</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'`^.*GoogleBot.*$`'</span><span style="color: #339933;">,</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Action</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStats</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' secondes'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Et le même avec strpos :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Benchmark.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Check this string for finding a GoogleBot !'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">300000</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'GoogleBot'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Action</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStats</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' secondes'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Ce test consiste simplement à trouver le mot &laquo;&nbsp;GoogleBot&nbsp;&raquo; dans une chaîne de caractères. Et voici le résultat :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/07/strpos_vs_preg_match.png"><img class="aligncenter size-full wp-image-454" title="strpos_vs_preg_match" src="http://www.exinsidephp.com/wp-content/uploads/2010/07/strpos_vs_preg_match.png" alt="" width="300" height="250" /></a></p>
<p>On remarque ici que l&#8217;expression régulière est <strong>11% plus lente</strong> que la fonction strpos, tout en considérant que plus la chaîne à analyser est longue, plus l&#8217;écart sera important. Il est donc préférable dans ce cas d&#8217;utiliser strpos plutôt qu&#8217;une expression régulière.</p>
<p>Dans le même esprit PHP a introduit récemment les fonctions <a title="Documention fonctions filter" href="http://fr.php.net/filter" target="_blank">filter</a>, il est ainsi possible de tester la validité d&#8217;une adresse email avec celles-ci. Mais qu&#8217;en est il question performance ? Nous allons pour ce faire reprendre les résultats lors de notre premier test avec preg_match et nous allons les confronter avec ce test :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Benchmark.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'info@e-ur-ope.a.n-cards.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$perf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">100000</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> FILTER_VALIDATE_EMAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$perf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStats</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' secondes'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Voici les résultats :</p>
<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/08/filter_var_vs_preg_match.png"><img class="aligncenter size-full wp-image-447" title="filter_var vs preg_match" src="http://www.exinsidephp.com/wp-content/uploads/2010/08/filter_var_vs_preg_match.png" alt="" width="300" height="250" /></a>On se rend malheureusement compte que la fonction filter_var est ainsi environ<strong> 10% plus lente </strong>que la fonction preg_match&#8230; Il y a encore du travail de ce coté, et pour ne pas arranger les choses le filtre <strong>FILTER_VALIDATE_EMAIL</strong> comporte de nombreux bugs&#8230; je vous déconseille donc de l&#8217;utiliser à l&#8217;heure actuelle et de préférer les expressions régulières.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 2323px; width: 1px; height: 1px; overflow: hidden;">&lt;?php<br />
include(&#8216;Benchmark.class.php&#8217;);</p>
<p>$var = &#8216;Check this string for finding a GoogleBot !&#8217;;<br />
$perf = new Benchmark();</p>
<p>for($i=0;$i&lt;100000;$i++){<br />
if(preg_match(&#8216;`^.*GoogleBot.*$`&#8217;,$var)){<br />
// Action<br />
}<br />
}</p>
<p>$perf-&gt;stop();<br />
echo $perf-&gt;getStats().&#8217; secondes&#8217;;<br />
?&gt;</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/07/02/optimisation-les-posix-ereg-et-les-pcre-preg/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Mise à jour: ExMail 2 Beta 2.1</title>
		<link>http://www.exinsidephp.com/2010/06/25/mise-a-jour-exmail-2-beta-2-1/</link>
		<comments>http://www.exinsidephp.com/2010/06/25/mise-a-jour-exmail-2-beta-2-1/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 21:02:37 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Les projets EXinsidePHP]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=435</guid>
		<description><![CDATA[Une petite mise à jour d&#8217;Exmail suite à quelques bugs reportés récemment par mail. Version BETA 2.1 : - Correction dé-sélection des checkboxs lors du succès de l&#8217;envoi - Ajout de la compatibilité avec l&#8217;option magic_quote_gpc activée Téléchargement d&#8217;EXmail]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Une petite mise à jour d&#8217;Exmail suite à quelques bugs reportés récemment par mail.</p>
<p style="text-align: justify;"><strong>Version BETA 2.1 :</strong></p>
<p style="text-align: justify;">- Correction dé-sélection des checkboxs lors du succès de l&#8217;envoi<br />
- Ajout de la compatibilité avec l&#8217;option magic_quote_gpc activée</p>
<p style="text-align: center;"><a href="http://www.exinsidephp.com/exmail/">Téléchargement d&#8217;EXmail</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/06/25/mise-a-jour-exmail-2-beta-2-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMemCacheAdmin &#8211; Administration, Monitoring et Debug de serveur Memcache</title>
		<link>http://www.exinsidephp.com/2010/06/25/phpmemcacheadmin-administration-monitoring-et-debug/</link>
		<comments>http://www.exinsidephp.com/2010/06/25/phpmemcacheadmin-administration-monitoring-et-debug/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 12:23:00 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Administration serveur]]></category>
		<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[php5-memcache]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=425</guid>
		<description><![CDATA[Lorsque l&#8217;on installe un serveur Memcache, ou tout autre application serveur, on aime avoir des outils permettant de faire du monitoring. Lors de mes recherches pour faire ceci avec Memcache je suis tombé sur quelques pistes comme Hyperic (Application complète de monitoring) ou encore Memcache.php (Non maintenu depuis 2ans&#8230;). Cependant ce sont des projets qui,]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><a href="http://www.exinsidephp.com/wp-content/uploads/2010/06/phpmemcacheadmin.png"><img class="size-medium wp-image-427 alignleft" title="phpMemCacheAdmin" src="http://www.exinsidephp.com/wp-content/uploads/2010/06/phpmemcacheadmin-300x290.png" alt="" width="300" height="290" /></a>Lorsque l&#8217;on installe un serveur Memcache, ou tout autre application serveur, on aime avoir des outils permettant de faire du monitoring. Lors de mes recherches pour faire ceci avec Memcache je suis tombé sur quelques pistes comme <a title="Hyperic" href="http://www.hyperic.com/" target="_blank">Hyperic</a> (Application complète de monitoring) ou encore <a title="Memcache.php" href="http://livebookmark.net/journal/2008/05/21/memcachephp-stats-like-apcphp/" target="_blank">Memcache.php</a> (Non maintenu depuis 2ans&#8230;). Cependant ce sont des projets qui, soit ne sont plus maintenus, soit ils sont plutôt lourds et trop généralistes&#8230;</p>
<p><span id="more-425"></span></p>
<p style="text-align: justify;">C&#8217;est ainsi que j&#8217;ai découvert le très récent <a title="phpMemCacheAdmin" href="http://code.google.com/p/phpmemcacheadmin/" target="_blank">phpMemCacheAdmin</a> dont vous pouvez avoir à aperçu dans le screen ci-joint. Cette application est en PHP est s&#8217;installe très simplement, dans mon cas le serveur étant sur la même machine je n&#8217;ai même pas eu besoin de le configurer&#8230; Vous devrez tout de même penser à mettre un htaccess pour sécuriser  l&#8217;accès à l&#8217;application. Une fois installée vous pouvez ainsi avoir toutes les statistiques de votre serveur memcache, avoir des statistiques en temps réelle mais aussi insérer, supprimer des valeurs dans le cache etc&#8230;</p>
<p style="text-align: justify;">Le tout avec un interface claire, un code propre et une utilisation on ne peu plus simple. L&#8217;auteur semble être très actif sur le projet qui est peu connu à l&#8217;heure actuelle et mérite un peu plus de reconnaissance <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . Le seul gros manque, à mon goût, est de ne pas avoir accès à une liste des variables actuellement en cache sur le serveur, mis à par ça je vous le recommande chaudement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/06/25/phpmemcacheadmin-administration-monitoring-et-debug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAJ: Optimiser les performances Mysql/Apache/PHP</title>
		<link>http://www.exinsidephp.com/2010/06/23/optimiser-les-performances-mysqlapachephp/</link>
		<comments>http://www.exinsidephp.com/2010/06/23/optimiser-les-performances-mysqlapachephp/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 12:36:30 +0000</pubDate>
		<dc:creator>Steuf</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Optimisation]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[malloc]]></category>
		<category><![CDATA[mult-thread]]></category>

		<guid isPermaLink="false">http://www.exinsidephp.com/?p=420</guid>
		<description><![CDATA[Lorsque que l&#8217;on développe un projet sous PHP/Mysql/Apache, une fois celui-ci en production il nous arrive souvent de chercher à maximiser les performances de l&#8217;application pour exploiter au maximum les capacités de la (ou les) machine qui héberge le projet. L&#8217;optimisation se situe à deux niveaux, optimisation des algorithmes (qui est celle qui apporte le]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.exinsidephp.com/wp-content/uploads/2010/06/optimisation.jpg"><img class="alignleft size-thumbnail wp-image-421" title="Performance" src="http://www.exinsidephp.com/wp-content/uploads/2010/06/optimisation-150x150.jpg" alt="" width="150" height="150" /></a>Lorsque que l&#8217;on développe un projet sous PHP/Mysql/Apache, une fois celui-ci en production il nous arrive souvent de chercher à maximiser les performances de l&#8217;application pour exploiter au maximum les capacités de la (ou les) machine qui héberge le projet. L&#8217;optimisation se situe à deux niveaux, optimisation des algorithmes (qui est celle qui apporte le plus de performances infine) et l&#8217;optimisation des configurations sur la machine.</p>
<p>Grâce à <a title="Google" href="http://www.google.fr" target="_blank">Google</a> je vais vous partager une petite astuce permettant de gagner <strong>15 à 20%</strong> de performances supplémentaires sur <strong>Mysql</strong> (vérifié), ainsi que pour PHP et Apache (par extension je n&#8217;ai pas vérifié avec des benchmarks). En bref, de quoi augmenter de façon significative les temps de réponse de vos pages&#8230;</p>
<p><span id="more-420"></span></p>
<p>Sachant qu&#8217;aujourd&#8217;hui <a title="SEO – Google prend en compte la rapidité de votre site !" href="http://www.exinsidephp.com/2010/04/13/seo-google-prend-en-compte-la-rapidite-de-votre-site/">Google considère les temps de réponse de vos pages</a> dans son indexation, il est donc important de chercher à les améliorer et donc d&#8217;effectuer quelques optimisations de code et de configuration. On utilisera pour se faire la librairie <strong>tcmalloc</strong> venant des <a title="Google Perftools" href="http://code.google.com/p/google-perftools/" target="_blank"><strong>Google Perftools</strong></a>. Cette librairie optimise l&#8217;utilisation de <strong>malloc()</strong> en C/C++ au niveau de la gestion de la mémoire dans un environnement multi-thread.</p>
<p><strong>MAJ:</strong> <a title="DotDeb" href="http://www.dotdeb.org/" target="_blank">DotDeb</a> nous fourni aujourd&#8217;hui tout ce qu&#8217;il faut dans leurs dépôts c&#8217;est donc désormais bien plus simple pour maintenir cette librairie, procédez donc comme ceci :</p>
<p>Ajoutez (si cela n&#8217;est pas déjà fait) les lignes suivantes au fichier sources.list de APT:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>packages.dotdeb.org oldstable all
deb-src http:<span style="color: #000000; font-weight: bold;">//</span>packages.dotdeb.org oldstable all</pre></div></div>

<p>Remplacez &laquo;&nbsp;oldstable&nbsp;&raquo; par &laquo;&nbsp;stable&nbsp;&raquo; si vous utilisez la dernière version de <strong>Debian (Squeeze)</strong>, oldstable n&#8217;est valable que pour <strong>Debian Lenny</strong>.</p>
<p>Ensuite mettez à jour vos listes :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update</pre></div></div>

<p>Si vous avez une erreur du type :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">GPG error: http:<span style="color: #000000; font-weight: bold;">//</span>packages.dotdeb.org oldstable Release: 
The following signatures couldn<span style="color: #ff0000;">'t be verified because the public key is not available</span></pre></div></div>

<p>Exécutez les lignes de commandes suivantes :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gpg <span style="color: #660033;">--keyserver</span> keys.gnupg.net <span style="color: #660033;">--recv-key</span> 89DF5277
gpg <span style="color: #660033;">-a</span> <span style="color: #660033;">--export</span> 89DF5277 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">apt-key</span> add -</pre></div></div>

<p>Puis installé le paquet désiré :</p>
<pre>apt-get install libtcmalloc-minimal0</pre>
<p>Maintenant il va falloir modifier les bash de lancement de Mysql et d&#8217;Apache comme ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql</pre></div></div>

<p>Juste après :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Ajoutez :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LD_PRELOAD</span>=<span style="color: #ff0000;">&quot;/usr/lib/libtcmalloc_minimal.so.0&quot;</span><span style="color: #000000; font-weight: bold;">&lt;</span>span <span style="color: #007800;">class</span>=<span style="color: #ff0000;">&quot;Apple-style-span&quot;</span> <span style="color: #007800;">style</span>=<span style="color: #ff0000;">&quot;font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 19px; white-space: normal;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;/</span>span<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Il vous reste désormais à les relancer :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql stop
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql start</pre></div></div>

<p>Question performance j&#8217;ai bien noté le gain assez perceptible sous Mysql. Pour Apache je viens de l&#8217;intégrer dans l&#8217;espoir que PHP, étant en module de celui-ci, en tire parti. Je n&#8217;ai pas fait de benchmark donc si vous pouvez tester de votre coté et signaler l&#8217;utilité ou non de le mettre sur Apache, n&#8217;hésitez pas <img src='http://www.exinsidephp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p><strong>MAJ: </strong>N&#8217;aillant pas constaté de différence notable il est préférable de ne pas l&#8217;ajouter sur Apache, j&#8217;ai donc supprimé la partie &laquo;&nbsp;Apache&nbsp;&raquo; de ce tutoriel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exinsidephp.com/2010/06/23/optimiser-les-performances-mysqlapachephp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached

Served from: www.exinsidephp.com @ 2012-02-05 06:14:21 -->
