<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://www.martiusweb.net/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Martius Web</title>
  <link>http://www.martiusweb.net/</link>
  <atom:link href="http://www.martiusweb.net/feed/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>fr</language>
  <pubDate>Mon, 08 Mar 2010 08:24:50 +0100</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Nouveaux brouillons pour HTML 5 publiés par le W3C</title>
    <link>http://www.martiusweb.net/post/Nouveaux-brouillons-pour-HTML-5-publi%C3%A9s-par-le-W3C</link>
    <guid isPermaLink="false">urn:md5:d1478eb4a7221830d1acb8143254a9a8</guid>
    <pubDate>Fri, 05 Mar 2010 20:43:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Les articles</category>
        <category>HTML 5</category><category>navigateurs</category><category>SVG</category><category>W3C</category>    
    <description>    &lt;p&gt;Le W3C, organisme de définition et de normalisation des langages qui font le web, a publié aujourd&amp;#8217;hui sept documents sur HTML 5.&lt;/p&gt;
&lt;p&gt;Ceux-ci sont toujours à l&amp;#8217;état de &amp;#8220;brouillons&amp;#8221; (&lt;em&gt;drafts&lt;/em&gt;), qui ont pour objectif, notamment, de permettre aux navigateurs de se préparer à implémenter les nouvelles fonctionnalités et de recueillir des commentaires de la part des contributeurs/utilisateurs.&lt;/p&gt;
&lt;p&gt;Les principaux documents sont le brouillon de &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/TR/2010/WD-html5-20100304/&quot;&gt;la spécification HTML 5&lt;/a&gt;, les &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/TR/2010/WD-html5-diff-20100304/&quot;&gt;différences entre HTML 4 et HTML 5&lt;/a&gt;, ou encore le document de &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/TR/2010/WD-html-markup-20100304/&quot;&gt;spécification du langage HTML&lt;/a&gt;, se voulant être la référence du langage pour les intégrateurs souhaitant se conformer aux standards HTML. Contrairement à la spécification HTML 5, celui-ci ne vise pas a détailler le comportement prévu des navigateurs vis à vis des balises.&lt;/p&gt;
&lt;p&gt;On apprend également que les canevas 2D et micro-données, jusqu&amp;#8217;alors intégrés à HTML 5 ont maintenant leurs propres spécifications&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://www.w3.org/TR/2010/WD-2dcontext-20100304/&quot;&gt;HTML Canvas
2D Context&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.w3.org/TR/2010/WD-microdata-20100304/&quot;&gt;HTML
Microdata&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Enfin, les deux derniers documents concernent l&amp;#8217;intégration du &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/TR/2010/WD-rdfa-in-html-20100304/&quot;&gt;framework RDF en HTML 5&lt;/a&gt; et &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/TR/2010/WD-html-bidi-20100304/&quot;&gt;la réalisation de pages bi-directionnelles&lt;/a&gt; (dont le texte va de gauche à droite et droite à gauche).&lt;/p&gt;
&lt;p&gt;L&amp;#8217;information &lt;a hreflang=&quot;en&quot; href=&quot;http://www.w3.org/News/2010#entry-8735&quot;&gt;vient bien sûr du W3C&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Nouveaux-brouillons-pour-HTML-5-publi%C3%A9s-par-le-W3C#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Nouveaux-brouillons-pour-HTML-5-publi%C3%A9s-par-le-W3C#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/157</wfw:commentRss>
      </item>
    
  <item>
    <title>PHP et les sessions : durée de vie, utilisation avancée et quelques subtilités</title>
    <link>http://www.martiusweb.net/post/PHP-sessions-lifetime-utilisation-avancee-subtilites</link>
    <guid isPermaLink="false">urn:md5:27d7234e6187e3c324f00e2e195e10e5</guid>
    <pubDate>Thu, 18 Feb 2010 16:21:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Programmation PHP</category>
        <category>Ajax</category><category>php</category><category>programmation</category><category>réseau</category><category>sessions</category>    
    <description>&lt;p&gt;PHP met à disposition un ensemble de fonctions permettant de manipuler un mécanisme de sessions&amp;#160;: un moyen efficace de conserver des données entre deux requêtes avec lequel vous êtes probablement familier. On s&amp;#8217;en passe difficilement sur un site internet interactif&amp;#160;!&lt;/p&gt;
&lt;p&gt;Bien que ce mécanisme soit assez simple à manipuler, il reste néanmoins quelques subtilités qu&amp;#8217;il faut connaître pour en profiter pleinement et éviter des erreurs regrettables. On s&amp;#8217;intéressera tout particulièrement à la durée de vie des sessions.&lt;/p&gt;    &lt;p&gt;Le mécanisme des sessions de PHP peut se comprendre assez simplement. Le serveur attribue un identifiant unique à l&amp;#8217;utilisateur, qui sera retransmis à chaque requête (par le biais d&amp;#8217;un cookie ou d&amp;#8217;une variable dans l&amp;#8217;URL). PHP utilisera cet identifiant pour retrouver les données de l&amp;#8217;utilisateur qu&amp;#8217;il stocke sur le serveur.&lt;/p&gt;
&lt;p&gt;Dans un script php, une session démarre lors d&amp;#8217;un appel à la fonction &lt;code&gt;session_start()&lt;/code&gt;, cet appel est implicite si la directive &lt;code&gt;session.auto_start&lt;/code&gt; du &lt;code&gt;php.ini&lt;/code&gt; vaut &lt;code&gt;on&lt;/code&gt;. Si aucun identifiant de session n&amp;#8217;a été transmis dans la requête, alors PHP générera une valeur aléatoire renvoyée à l&amp;#8217;utilisateur. Si un identifiant existe, PHP remplira la variable globale &lt;code&gt;$_SESSION&lt;/code&gt; des données enregistrées.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Initialisation des sessions&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/session_start&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_start&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// On accède à une variable de session, et&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// on l'écrit si elle n'existe pas encore&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'bar'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// La variable est utilisable dans le script courant&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Les fonctions &lt;code&gt;session_register()&lt;/code&gt; et &lt;code&gt;session_unset()&lt;/code&gt; ne doivent plus être utilisées (elles sont considérées comme obsolètes).&lt;/p&gt;
&lt;h3&gt;Gestion des accès concurrents&lt;/h3&gt;
&lt;p&gt;Les données de sessions sont protégées en écritures&amp;#160;: cela signifie qu&amp;#8217;un seul script à la fois sera en mesure de les modifier. Ce comportement peut ralentir l&amp;#8217;exécution de requêtes simultanées (avec les frames ou Ajax par exemple), l&amp;#8217;enregistrement de la session sera retardé en attendant le (ou les) autre(s) script(s) soi(en)t terminé(s). Pour limiter cette attente, vous pouvez appeler explicitement la fonction &lt;code&gt;session_write_close()&lt;/code&gt; (ou son alias &lt;code&gt;session_commit()&lt;/code&gt;).&lt;/p&gt;
&lt;h3&gt;Sécurité&lt;/h3&gt;
&lt;p&gt;Fondamentalement, l&amp;#8217;implémentation des sessions en PHP ne souffre pas de problèmes de sécurité, mais vous devrez néanmoins veiller à la manière dont vous les utiliserez. En effet, dans la mesure où une session est basée sur un identifiant transmis sur internet entre l&amp;#8217;utilisateur et le serveur, cette donnée est très sensible. Si une personne mal intentionnée obtient l&amp;#8217;identifiant de session d&amp;#8217;un autre utilisateur, il devient assez facile d&amp;#8217;usurper son identité.&lt;/p&gt;
&lt;p&gt;Il existe plusieurs techniques (simples ou plus compliquées) permettant d&amp;#8217;obtenir l&amp;#8217;identifiant de session d&amp;#8217;un utilisateur&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;la capture&amp;#160;: c&amp;#8217;est simplement le vol de l&amp;#8217;identifiant en le lisant chez l&amp;#8217;utilisateur (risque qui doit être contrôlé par l&amp;#8217;utilisateur),&lt;/li&gt;
&lt;li&gt;la divination&amp;#160;: l&amp;#8217;identifiant est deviné par la personne mal intentionnée (pratiquement impossible),&lt;/li&gt;
&lt;li&gt;la fixation&amp;#160;: le pirate choisit et force l&amp;#8217;identifiant de la session (que l&amp;#8217;on peut éviter simplement).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;D&amp;#8217;une manière générale, on évitera de transmettre l&amp;#8217;identifiant de session dans l&amp;#8217;URL par sécurité (pour prévenir de la fixation). D&amp;#8217;ailleurs, c&amp;#8217;est assez mauvais pour le référencement. Ce comportement peut être désactivé avec la directive &lt;code&gt;session.use_only_cookies&lt;/code&gt; à vrai. Bien entendu, un utilisateur interdisant l&amp;#8217;utilisation des cookies ne pourra pas utiliser les sessions.&lt;/p&gt;
&lt;p&gt;Dans tous les cas, quand le niveau de sensibilité d&amp;#8217;une session est modifié (par exemple, quand l&amp;#8217;utilisateur s&amp;#8217;authentifie ou qu&amp;#8217;il obtient de nouveaux droits d&amp;#8217;accès), une bonne pratique consiste à générer de nouveau cet identifiant de session avec la fonction &lt;code&gt;session_regenerate_id()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Par défaut, les données de sessions de PHP sont stockées dans un simple fichier de texte (dans le répertoire &lt;code&gt;/tmp&lt;/code&gt; sous linux). Tous les scripts PHP peuvent lire ces fichiers car toute exécution de PHP est réalisée par un même utilisateur (à moins que le &lt;code&gt;safe_mode&lt;/code&gt; soit activé). Sur un hébergeur mutualisé, il est peut-être plus prudent de stocker les données de sessions dans une base de données. Consultez la documentation de la fonction &lt;a hreflang=&quot;fr&quot; href=&quot;http://fr.php.net/manual/fr/function.session-set-save-handler.php&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;&lt;code&gt;session_set_save_handler()&lt;/code&gt;&lt;/a&gt; pour en savoir plus sur la personnalisation de la gestion du stockage des données de sessions.&lt;/p&gt;
&lt;h3&gt;Durée de vie&lt;/h3&gt;
&lt;p&gt;L&amp;#8217;un des points les plus délicats à appréhender dans le mécanisme des sessions concerne la durée de vie. Dans cette section, nous allons voir qu&amp;#8217;il y a plusieurs facteurs qui permettent de déterminer la durée de vie d&amp;#8217;une session.&lt;/p&gt;
&lt;p&gt;On doit, dans un premier temps, distinguer le cas pour lequel l&amp;#8217;identifiant de session est transmis par l&amp;#8217;URL de celui où un cookie est utilisé.&lt;/p&gt;
&lt;p&gt;Dans le premier cas, la session existera tant que l&amp;#8217;identifiant sera transmis par l&amp;#8217;URL. En fait, même recopiant la même adresse dans un autre navigateur, la session sera retrouvée.&lt;/p&gt;
&lt;p&gt;Si on utilise un cookie, la durée de vie d&amp;#8217;une session dépendra de la durée de vie d&amp;#8217;un cookie. Cette durée est définie à l&amp;#8217;aide de la directive &lt;code&gt;session.cookie_lifetime&lt;/code&gt;. Si cette valeur vaut 0, alors le cookie sera maintenu par le navigateur tant que ce dernier ne sera pas quitté par l&amp;#8217;utilisateur.&lt;/p&gt;
&lt;p&gt;La plupart des directives de manipulation des sessions définies dans la configuration de PHP peuvent être modifiées dynamiquement pour un script, à condition que ces modifications interviennent avant le démarrage d&amp;#8217;une session avec &lt;code&gt;session_start()&lt;/code&gt;. Si le démarrage automatique est actif, vous ne pourrez pas manipuler ces valeurs. Pour pouvoir faire quelques tests, j&amp;#8217;ai utilisé la fonction &lt;a hreflang=&quot;fr&quot; href=&quot;http://fr.php.net/session_set_cookie_params&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;&lt;code&gt;session_set_cookie_params()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Le script qui suit affiche la durée de vie restante du cookie de session et une chaine de caractère définie à la création de la session. Tant que cette valeur ne change pas, cela signifie que la session utilisée est toujours la même.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Durée de vie de la session (Time To Live)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/session_set_cookie_params&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_set_cookie_params&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/session_start&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_start&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;||&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;&lt;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'bar'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'bar'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/uniqid&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;uniqid&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;time&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'TTL de la session ('&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'bar'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;') : '&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_SESSION&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'foo'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;&lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;time&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Voici quelques tests que j&amp;#8217;ai effectué&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;En choisissant la valeur 10 pour la variable &lt;code&gt;$ttl&lt;/code&gt; et en actualisant régulièrement la page, on voit la valeur TTL diminuer puis la session se renouveler (nouvelle chaine de caractère affichée);&lt;/li&gt;
&lt;li&gt;En choisissant la valeur 60, j&amp;#8217;ai eu le temps de relancer mon navigateur avant la suppression du cookie, et de constater que la session était toujours active;&lt;/li&gt;
&lt;li&gt;En choisissant la valeur 0, la session était toujours active plus d&amp;#8217;une heure après sa création, mais elle n&amp;#8217;a pas résisté à la fermeture d&amp;#8217;un navigateur.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Ramasse-miettes&lt;/h3&gt;
&lt;p&gt;Nous avons vu ce qui causait la mort d&amp;#8217;une session du côté du client, mais lorsque le cookie est supprimé, ou que l&amp;#8217;identifiant n&amp;#8217;est plus transmis, les données stockées sur le serveur ne sont pas supprimées pour autant.&lt;/p&gt;
&lt;p&gt;PHP a donc mis en place un système de ramasse-miettes (ou &lt;em&gt;garbage collector&lt;/em&gt; en anglais) chargé de supprimer ces données persistantes au bout d&amp;#8217;un certain temps. Cependant, ce temps n&amp;#8217;est pas nécessairement le même que celui de la durée de vie du cookie.&lt;/p&gt;
&lt;p&gt;La durée de vie des données sur le serveur est définie par la directive &lt;code&gt;session.gc_maxlifetime&lt;/code&gt;. Si les données ont été supprimées du serveur avant que la session ait expirée chez le client, cette dernière est tout de même réinitialisée. Il faut donc considérer (et c&amp;#8217;est bien théorique, voir ci-dessous) que la durée de vie réelle d&amp;#8217;une session est la plus petite des valeurs entre la durée de vie du cookie et la durée de vie des données sur le serveur.&lt;/p&gt;
&lt;p&gt;La donnée ne sera effectivement supprimée que lorsque le ramasse-miette sera appelé. Cette action est effectuée aléatoirement lors du démarrage de la session, la probabilité de son déclenchement est défini par deux directives&amp;#160;: &lt;code&gt;session.gc_probability&lt;/code&gt; et &lt;code&gt;session.gc_divisor&lt;/code&gt;. On a donc&amp;#160;:&lt;/p&gt;
&lt;pre&gt;probabilité d'appel = gc_probability/gc_divisor&lt;/pre&gt;&lt;p&gt;Les valeurs par défaut sont respectivement 1 et 100, la probabilité est donc 1/100.&lt;/p&gt;
&lt;h3&gt;Assurer la durée de vie de la session&lt;/h3&gt;
&lt;p&gt;Si vous choisissez de modifier la durée de vie de la session du côté du client (avec &lt;code&gt;session_set_cookie_params()&lt;/code&gt;), il faudra appliquer les mêmes règles au ramasse-miettes. Cette opération ne peut être effectuée qu&amp;#8217;en modifiant la directive &lt;code&gt;session.gc_maxlifetime&lt;/code&gt; de &lt;code&gt;php.ini&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Il est tout à fait possible de faire cette modification avec la fonction &lt;code&gt;ini_set()&lt;/code&gt;, mais il faudra prendre certaines précautions. En effet&amp;#160;: l&amp;#8217;appel à &lt;code&gt;ini_set()&lt;/code&gt; modifie dynamiquement la configuration, ainsi, lors d&amp;#8217;une autre exécution, PHP considérera la valeur écrite statiquement dans les fichiers de configuration. Au passage, ce raisonnement est également valable lorsque la valeur de la directive est modifiée dans un fichier htaccess. Afin de garantir la durée de vie souhaitée à nos données de sessions, la méthode la plus simple consiste à les rendre inconnues pour un autre script&amp;#160;; autrement dit, s&amp;#8217;affranchir plus profondément de la configuration statique de PHP.&lt;/p&gt;
&lt;p&gt;La solution la plus simple consiste à choisir un autre répertoire de stockage des données de session, un sous-répertoire par exemple&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Une heure, en secondes&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$local_sessions_save_path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/ini_get&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ini_get&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'session.save_path'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/monsiteweb'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/session_set_cookie_params&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_set_cookie_params&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/ini_set&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ini_set&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'session.gc_maxlifetime'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$ttl&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/ini_set&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;ini_set&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'session.save_path'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$local_sessions_save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/session_start&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;session_start&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Avec cette solution, le garbage collector appelé dans le contexte d&amp;#8217;un autre script supprimera les sessions périmées dans le répertoire défini par &lt;code&gt;session.save_path&lt;/code&gt;, et non le sous répertoire que nous avons choisi. Pensez quand même à créer ce sous-répertoire&amp;#160;!&lt;/p&gt;
&lt;h3&gt;Liaison d&amp;#8217;autres données à la session&lt;/h3&gt;
&lt;p&gt;Dans certains cas, on peut souhaiter sauvegarder des donnés liées à une session sans utiliser la variable &lt;code&gt;$_SESSION&lt;/code&gt;&amp;#160;: un fichier envoyé par l&amp;#8217;utilisateur, des données temporaires dans une base de données, etc.&lt;/p&gt;
&lt;p&gt;Ces données ne seront pas supprimées par l&amp;#8217;implémentation par défaut du ramasse-miettes. Nous allons donc devoir surcharger le gestionnaire de sessions par défaut, composé de six fonctions, qui se chargeront de&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;l&amp;#8217;ouverture de la session,&lt;/li&gt;
&lt;li&gt;la fermeture,&lt;/li&gt;
&lt;li&gt;la lecture des données de session,&lt;/li&gt;
&lt;li&gt;l&amp;#8217;écriture,&lt;/li&gt;
&lt;li&gt;la suppression de la session,&lt;/li&gt;
&lt;li&gt;le ramasse-miettes/garbage collector.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Une fois ces fonctions créés, il faudra les déclarer au moteur PHP avec &lt;a onclick=&quot;window.open(this.href); return false;&quot; hreflang=&quot;fr&quot; href=&quot;http://php.net/manual/fr/function.session-set-save-handler.php&quot;&gt;&lt;code&gt;session_set_save_handler()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Dans la suite de cet article, je vais surcharger le gestionnaire de sessions en reprenant le fonctionnement de celui apr défaut de PHP. Il est d&amp;#8217;ailleurs très largement issu de l&amp;#8217;exemple donné dans la documentation officielle. Dans certains cas, il aurait été utile de sauvegarder les données dans la base de données.&lt;/p&gt;
&lt;p&gt;J&amp;#8217;ai choisi d&amp;#8217;utiliser une classe statique (&lt;code&gt;MySessionHandler&lt;/code&gt;) pour centraliser ces fonctions, mais ce n&amp;#8217;est pas une obligation. &lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MySessionHandler&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  protected &lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * On interdit la construction, puisque ce n'est pas nécessaire.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; __construct&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Nous placerons ici les méthodes développées à la suite&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h4&gt;Ouverture de la session&lt;/h4&gt;
&lt;p&gt;La fonction d&amp;#8217;ouverture sera appelée avec deux paramètres&amp;#160;: le chemin de sauvegarde et le nom de la session. Ces données seront transmises par le moteur de PHP. Cette fonction se chargera de conserver, pour le script courant, le répertoire de sauvegarde des sessions. Dans la mesure où cette donnée est transmise par le moteur de PHP lui-même, les autres fonctions de manipulation des sessions que nous avons vu avant sont toujours fonctionnelles.&lt;/p&gt;
&lt;p&gt;Nous n&amp;#8217;avons pas besoin de l&amp;#8217;identifiant de session pour cette implémentation.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Méthode d'ouverture de la session, c'est&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $save_path&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $session_name&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return bool&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; open&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$session_name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;h4&gt;Fermeture de la session&lt;/h4&gt;
&lt;p&gt;Cette méthode est la plus simple&amp;#160;: puisque rien de particulier n&amp;#8217;est effectué à l&amp;#8217;ouverture de la session, on ne fait &lt;em&gt;rien&lt;/em&gt; à la fermeture&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Fermeture de la session, exécutée à la fin du script&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return bool&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; close&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h4&gt;Lecture des données&lt;/h4&gt;
&lt;p&gt;La lecture des données consiste à récupérer les données écrites dans un fichier avant une précédente fermeture. Il faut donc vérifier que la session existait déjà, et n&amp;#8217;a pas été supprimée.&lt;/p&gt;
&lt;p&gt;Cette fonction doit impérativement retourner une chaine de caractères (&lt;code&gt;string&lt;/code&gt;). Le moteur de PHP se charge lui-même de la sérialisation/désérialisation des données avant et après la lecture/écriture. Nous retournons donc directement le bloc de données lu, sans modifications&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Lecture des données de session sérialisées.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $id identifiant de la session&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return string&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; read&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$return&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/sess_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/is_readable&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_readable&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;       &lt;span style=&quot;color: #ff0000&quot;&gt;$return&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/file_get_contents&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_get_contents&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$return&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h4&gt;Écriture des données&lt;/h4&gt;
&lt;p&gt;De la même manière, on écrira le bloc de données transmis par PHP directement dans le fichier de session. La méthode prendra deux paramètres&amp;#160;: l&amp;#8217;identifiant de session, et le bloc de données.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Écriture des données de la session.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $id&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $data&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return bool&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; write&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$res&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/sess_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/is_writable&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_writable&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #ff0000&quot;&gt;$res&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; file_put_contents&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$res&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h4&gt;Destruction de la session et garbage collector&lt;/h4&gt;
&lt;p&gt;La suppression des données de session peut être effectuée à deux moments&amp;#160;: lors de sa destruction explicite (avec &lt;code&gt;session_destroy()&lt;/code&gt;) ou au passage du &lt;em&gt;garbage collector&lt;/em&gt;. Nous allons donc implémenter une méthode &lt;code&gt;delete()&lt;/code&gt; qui supprimera une session, et qui sera appelée par &lt;code&gt;destroy()&lt;/code&gt; et &lt;code&gt;gc()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Dans cet exemple, on supposera que certaines données, stockées dans un répertoire data/sessions/[identifiant de session] sont d&amp;#8217;autres données liées aux session que nous souhaitons supprimer. On peut également imaginer devoir supprimer des données dans une base de données.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Suppression des données d'une session.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $id&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return void&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  protected &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; delete&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;a href=&quot;http://www.php.net/unlink&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;unlink&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/sess_'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// on suppose ici que le répertoire de session n'a pas de sous-répertoire.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$sess_dir&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'data/sessions/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$to_delete&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; scandir&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_dir&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$to_delete&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'.'&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;||&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'..'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;a href=&quot;http://www.php.net/unlink&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;unlink&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_dir&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;a href=&quot;http://www.php.net/rmdir&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;rmdir&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$sess_dir&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Destruction de la session.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param string $id&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @return bool&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; destroy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;delete&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * Ramasse-miettes&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; * @param int $maxlifetime&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; gc&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$maxlifetime&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$toDelete&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/glob&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;glob&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$save_path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/sess_*'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$toDelete&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      self&lt;span style=&quot;color: #66cc66;&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;delete&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;h4&gt;Attention à l&amp;#8217;identifiant de session&amp;#160;!&lt;/h4&gt;
Dans notre exemple ci-dessus, on se base sur l&amp;#8217;identifiant de session pour connaître les fichiers associés à une session. N&amp;#8217;oubliez pas que cette pratique n&amp;#8217;est pas nécessairement idéale, puisque par sécurité, cet identifiant risque d&amp;#8217;être modifié&amp;#160;!&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Conclusions&lt;/h3&gt;
&lt;p&gt;Attention, cet article permet de comprendre quelques points importants, mais ne prétend naturellement être complet (on en est même loin&amp;#160;!). N&amp;#8217;oubliez pas de faire vos propres tests et de lire d&amp;#8217;autres articles pour en savoir plus, et plus particulièrement sur la sécurité, car je ne l&amp;#8217;ai développé que pour mettre en garde quand à l&amp;#8217;existence de risques liés aux sessions.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/PHP-sessions-lifetime-utilisation-avancee-subtilites#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/PHP-sessions-lifetime-utilisation-avancee-subtilites#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/153</wfw:commentRss>
      </item>
    
  <item>
    <title>Facebook distribue sous licence open-source un traducteur PHP vers C++</title>
    <link>http://www.martiusweb.net/post/Facebook-distribue-sous-licence-open-source-un-traducteur-PHP-vers-C</link>
    <guid isPermaLink="false">urn:md5:2488d50dec5bc4f981b9d7b09e542cc3</guid>
    <pubDate>Tue, 02 Feb 2010 23:41:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Programmation PHP</category>
        <category>création de sites web</category><category>développeur</category><category>optimisation</category><category>php</category><category>programmation</category><category>serveur</category>    
    <description>&lt;p&gt;&lt;img style=&quot;margin: 0 0 1em 1em; float: right;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/articles/.31_sq.jpg&quot; /&gt;L&amp;#8217;équipe des développeurs de Facebook a annoncé aujourd&amp;#8217;hui la distribution (dans un futur proche) d&amp;#8217;un outil permettant de traduire en C++ et compiler du code PHP&amp;#160;: &lt;em&gt;HipHop for PHP&lt;/em&gt;. D&amp;#8217;après l&amp;#8217;annonce officielle, cet outil permettrait à Facebook de réduire de près de 50% en moyenne la sollicitation du processeur sur la plupart des pages du service, dont le front-end a été essentiellement développé avec PHP.&lt;/p&gt;    &lt;p&gt;PHP est un langage de programmation qui offre de nombreux avantages&amp;#160;: une syntaxe souple, facile à apprendre et comprendre, une grande variété d&amp;#8217;outils simplifiant le développement, une bibliothèque de fonction couvrant la plupart des besoins des développeurs d&amp;#8217;applications web et c&amp;#8217;est un produit libre. Ces avantages se traduisent facilement en excellents rapports coûts/temps de développement, ce qui rend le choix de PHP dans un processus de développement agile encore plus pertinent.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;un autre côté, PHP est un langage interprété&amp;#160;: le fichier source sera de nouveau lu et traduit en langage machine avant chaque exécution. Des outils permettent de mettre en cache une partie de ce traitement (les &lt;em&gt;optimiseurs d&amp;#8217;opcode&lt;/em&gt;) améliorent sensiblement les performances d&amp;#8217;une exécution.&lt;em&gt;&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Pour les équipes d&amp;#8217;ingénieurs de  Facebook, ce n&amp;#8217;était probablement pas suffisant, car ils ont développé en interne &lt;em&gt;HipHop for PHP&lt;/em&gt;, afin de permettre à un script PHP d&amp;#8217;approcher les performances d&amp;#8217;un programme compilé en C++.&lt;/p&gt;
&lt;h3&gt;Des compilateurs PHP existent déjà, quelle est donc la valeur ajoutée de HipHop&amp;#160;?&lt;/h3&gt;
&lt;p&gt;Contrairement à &lt;a hreflang=&quot;en&quot; href=&quot;http://www.roadsend.com/home/index.php&quot;&gt;Roadsend&lt;/a&gt; ou &lt;a hreflang=&quot;en&quot; href=&quot;http://www.phpcompiler.org/&quot;&gt;phpcompiler&lt;/a&gt;, HipHop n&amp;#8217;est pas à proprement parler un compilateur. L&amp;#8217;outil est en fait une chaine de traitement qui mènent à une version compilée, mais passant par une phase de traduction du langage en C++ optimisé pour les besoins. On supposera déjà qu&amp;#8217;il est pratiquement inutile d&amp;#8217;essayer d&amp;#8217;analyser et modifier directement ce code C++ généré. Ce dernier sera compilé par le compilateur Gnu, g++.&lt;/p&gt;
&lt;p&gt;La traduction s&amp;#8217;effectue en trois étapes majeures&amp;#160;:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Une analyse statique permet de collecter les informations sur les déclarations et les dépendances entre les fichiers composant le script&amp;#160;: à priori, une table des symboles (classes/méthodes/fonctions) est dressée.&lt;/li&gt;
&lt;li&gt;Une seconde analyse permet de choisir le type C++ optimal utilisé pour les symboles et variables (j&amp;#8217;en reparle un peu plus bas).&lt;/li&gt;
&lt;li&gt;Enfin, les instructions en PHP sont traduites en C++. Cette opération est essentiellement une conversion syntaxique (les deux langages sont assez proches du point de vue de la syntaxe).&lt;/li&gt;
&lt;/ol&gt;
&lt;a href=&quot;http://www.martiusweb.net/public/articles/HipHop_transformation_process.png&quot;&gt;&lt;img title=&quot;Processus de conversion de PHP en C++ par HipHop&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/articles/.HipHop_transformation_process_m.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;h3&gt;Quelles sont les limites&amp;#160;?&lt;/h3&gt;
&lt;p&gt;A priori, la quasi-totalité de la grammaire du langage a été retranscrite, il est même probable que la plupart des librairies soient utilisables, dans la mesure où celles-ci, tout comme le moteur Zend de PHP, sont écrites en C.&lt;/p&gt;
&lt;p&gt;La plupart des gains réalisés proviennent de l&amp;#8217;optimisation de la &amp;#8220;magie&amp;#8221; de PHP, c&amp;#8217;est à dire, l&amp;#8217;ensemble des instructions qui nécessitent une évaluation dynamique. L&amp;#8217;exemple le plus évident est probablement le transtypage à la volée. En effet, dans la mesure où PHP est un langage faiblement typé, il est possible de manipuler une variable sans restreindre son type&amp;#160;: on peut facilement passer d&amp;#8217;un entier à une chaine de caractères, par exemple. Cette souplesse à un coût, puisque le moteur PHP doit évaluer et déterminer le type de l&amp;#8217;information manipulée (coût CPU), et en stocker une copie dans les principaux types (coût mémoire).&lt;/p&gt;
&lt;p&gt;HipHop ne remplacera naturellement pas le travail
d&amp;#8217;optimisation du développeur, il est même possible de s&amp;#8217;imposer
quelques nouvelles contraintes, comme limiter les transtypages implicites.&lt;/p&gt;
&lt;p&gt;Par ailleurs quelques fonctionnalités propres à un langage interprétés n&amp;#8217;ont pas été portées en raison de la complexité de l&amp;#8217;opération et du faible gain, comme la fonction &lt;code&gt;eval()&lt;/code&gt;. On peut tout de même supposer que les noms de symbôles obtenus dynamiquement (voir ci-dessous) fonctionneront, puisque je suppose qu&amp;#8217;on peut relativement facilement remplacer le mécanisme par des pointeurs sur fonctions en C++.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Manipulation dynamique de symbole : on instancie une&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// classe dont le nom est stocjé dans une variable&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classe&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'PDO'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$monObjet&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$classe&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// on vient d'appeler le constructeur de la classe PDO&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;h3&gt;En savoir plus&lt;/h3&gt;
&lt;p&gt;
Pour ce soir (heure française), on doit se contenter de cette annonce&amp;#160;: on ne sait pas encore exactement quelle licence sera choisie (on sait néanmoins que l&amp;#8217;outil sera opensource), le code n&amp;#8217;est pas encore disponible et le wiki mis en place n&amp;#8217;est pas encore public. J&amp;#8217;espère donc avoir rapidement l&amp;#8217;occasion et le temps de faire des tests et des comparatifs de performance (avec un framework comme symfony par exemple).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Mise à jour&amp;#160;:&lt;/em&gt; La licence retenue est la licence de PHP, le projet sera bientôt disponible publiquement sur &lt;a hreflang=&quot;en&quot; href=&quot;http://github.com/facebook/hiphop-php/wikis&quot;&gt;&lt;em&gt;le github de facebook&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;HipHop for PHP serait déjà utilisé en production sur Facebook, on peut donc supposer que la première version mis à disposition sera déjà stable et bien avancée.&lt;/p&gt;
&lt;p&gt;&lt;a hreflang=&quot;en&quot; href=&quot;http://developers.facebook.com/news.php?blog=1&amp;amp;story=358&quot;&gt;Annonce officielle sur le blog des développeurs de Facebook&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Facebook-distribue-sous-licence-open-source-un-traducteur-PHP-vers-C#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Facebook-distribue-sous-licence-open-source-un-traducteur-PHP-vers-C#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/152</wfw:commentRss>
      </item>
    
  <item>
    <title>BeGood Basketball Services</title>
    <link>http://www.martiusweb.net/post/BeGood-Basketball-Services</link>
    <guid isPermaLink="false">urn:md5:a274c7f72495916c2e153d1b882a770d</guid>
    <pubDate>Tue, 26 Jan 2010 17:12:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Nos réalisations</category>
            
    <description>    &lt;p&gt;&lt;a href=&quot;http://www.begood-basketball.com&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;&lt;img title=&quot;Be Good Basketball Services&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/realisations/begoodbasketball.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;BeGood Basketball services est une agence de placement de joueurs et
de joueuses de basket professionnel. Martius Web à réalisé la charte graphique, l&amp;#8217;intégration à Dotclear et un module d&amp;#8217;accès restreint pour limiter la consultation des données des joueurs aux visiteurs s&amp;#8217;étant enregistrés.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.begood-basketball.com&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;Visiter le Site Begood Basketball Services&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/BeGood-Basketball-Services#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/BeGood-Basketball-Services#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/150</wfw:commentRss>
      </item>
    
  <item>
    <title>Étudiant et Auto-entrepreneur : interview par La Manu</title>
    <link>http://www.martiusweb.net/post/%C3%89tudiant-et-Auto-entrepreneur-%3A-interview-par-La-Manu</link>
    <guid isPermaLink="false">urn:md5:75df341131ad978405e126040d89fab9</guid>
    <pubDate>Thu, 05 Nov 2009 21:57:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Actualités de Martius Web</category>
        <category>AE</category><category>auto-entrepreneur</category><category>interview</category><category>étudiant</category>    
    <description>&lt;p&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.la-manu.fr/&quot;&gt;La manu&lt;/a&gt; &amp;#8220;fabrique
le lien entre les étudiants et les entreprises&amp;#8221;, par le biais de
plusieurs actions, dont la publication d&amp;#8217;un magazine à destination des
étudiants de la fac. Dans le cadre d&amp;#8217;un &lt;a hreflang=&quot;fr&quot; href=&quot;http://la-manu.fr/300-000-auto-entrepreneurs-et-moi-et-moi-et-moi.html&quot;&gt;article sur l&amp;#8217;auto-entrepreneur&lt;/a&gt;, on trouve notamment une intervention de votre serviteur&amp;#160;!&lt;/p&gt;
&lt;p&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://la-manu.fr/300-000-auto-entrepreneurs-et-moi-et-moi-et-moi.html&quot;&gt;Lire l&amp;#8217;article &amp;#8220;300&amp;#160;000 auto-entrepreneurs et moi, et moi, et moi&amp;#160;?&amp;#8221;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;&lt;img title=&quot;Logo de La Manu, nov. 2009&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://blog.martiusweb.net/public/novembre/n34151645325_969.jpg&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Une opportunité tout aussi&amp;nbsp;intéressante pour les étudiants qui veulent
tester une idée ou financer leurs études. Du haut de ses 19 ans, Martin
Richard conciliait DUT Informatique et services en développement de
sites Internet dès le mois de février. Il s&amp;#8217;est lancé avec 70 euros
(pour ses cartes de visite) et l&amp;#8217;aide de ses profs pour la rédaction
des contrats et les aspects administratifs et comptables.&lt;/p&gt;
&lt;p&gt;«&amp;#160;Quand
les gens me rencontrent, ils ne sont pas rassurés en raison de mon âge,
reconnaît-il. Mais ils finissent par me faire confiance.&amp;#160;» Sa technique
? La création d&amp;#8217;un réseau qui débute par les cercles proches&amp;nbsp;- famille,
amis de la famille, etc., la publication régulière d&amp;#8217;articles dans un
magazine spécialisé et des risques bien calculés.&lt;/p&gt;
&lt;p&gt;Martin mène bien sa barque, il n&amp;#8217;en demeure pas moins que ses semaines
sont très chargées et ses responsabilités importantes. De plus, il
poursuit ses études en Master cette année.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://la-manu.fr/300-000-auto-entrepreneurs-et-moi-et-moi-et-moi.html&quot;&gt;Lire l&amp;#8217;article &amp;#8220;300&amp;#160;000 auto-entrepreneurs et moi, et moi, et moi&amp;#160;?&amp;#8221;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.la-manu.fr/&quot;&gt;site internet de La Manu&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.facebook.com/pages/La-Manu/34151645325&quot;&gt;Page facebook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/%C3%89tudiant-et-Auto-entrepreneur-%3A-interview-par-La-Manu#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/%C3%89tudiant-et-Auto-entrepreneur-%3A-interview-par-La-Manu#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/143</wfw:commentRss>
      </item>
    
  <item>
    <title>PHP Solutions : Robots d'indexation et référencement</title>
    <link>http://www.martiusweb.net/post/PHP-Solutions-%3A-Robots-d-indexation-et-r%C3%A9f%C3%A9rencement</link>
    <guid isPermaLink="false">urn:md5:1d1fa53ee67ef04ed5ab52cb8887305c</guid>
    <pubDate>Wed, 04 Nov 2009 23:33:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Programmation PHP</category>
        <category>bases</category><category>création de sites web</category><category>php</category><category>POO</category><category>programmation</category><category>référencement</category><category>SEO</category>    
    <description>&lt;p&gt;&lt;em&gt;Article paru dans le magazine &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.phpsolmag.org/&quot;&gt;PHP Solutions&lt;/a&gt;&amp;nbsp;(Août 2008). Attention cet article n&amp;#8217;est pas soumis à la licence Creative
Commons&amp;#160;: tous les droits de cet article sont réservés.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;La visibilité de votre site internet est l&amp;#8217;un des principaux atouts de son succès, et la maîtrise des moteurs de recherche et du référencement peut vous faire gagner de précieuses visites.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note&amp;#160;: Cet article contient plusieurs références n&amp;#8217;étant pas à jour, notamment concernant les informations techniques liées aux traces laissées par les robots d&amp;#8217;indexation des moteurs de recherche sur votre site, ou même le nom du moteur de recherche de Microsoft (qui s&amp;#8217;appelle maintenant Bing, mais vous le savez déjà).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Cet article explique&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Les bases d&amp;#8217;un algorithme d&amp;#8217;exploration et d&amp;#8217;indexation du web,&lt;/li&gt;
&lt;li&gt;Les principales règles d&amp;#8217;optimisation du référencement (SEO),&lt;/li&gt;
&lt;li&gt;Comment concevoir un terrain d&amp;#8217;accueil pour améliorer l&amp;#8217;expérience de l&amp;#8217;utilisateur.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ce qu&amp;#8217;il faut savoir&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Les principaux éléments de la syntaxe des expressions régulières,&lt;/li&gt;
&lt;li&gt;Des bonnes notions du langage PHP et les bases de la programmation orientée objet.&lt;/li&gt;
&lt;/ul&gt;    &lt;p&gt;Vous allez voir dans les grandes lignes comment se comporte un robot d&amp;#8217;indexation (ou &lt;em&gt;spider&lt;/em&gt;) afin de mieux en comprendre le fonctionnement. Pour cela, vous allez tenter de concevoir le notre. Un robot est un programme chargé de parcourir automatiquement le web pour enregistrer des informations issues des documents visités.La plupart du temps, les robots ne sont capables d&amp;#8217;analyser que du contenu textuel, ce qui correspond à un grand nombre de types de fichiers. Le contenu binaire comme les images, la musique ou les vidéos est beaucoup plus difficile à indexer, c&amp;#8217;est pourquoi nous n&amp;#8217;en parlerons pas dans cette partie.&lt;/p&gt;
&lt;p&gt;Les robots d&amp;#8217;indexation sont utilisés par les moteurs de recherche avant tout, pour alimenter leur base de données. Mais ils sont aussi utilisés dans des outils de veille, souvent dans des projets d&amp;#8217;études universitaires, comme les outils de statistiques d&amp;#8217;utilisation et de modification du contenu de wikipédia, ou encore les institutions ou organismes nationaux chargés de contrôler pour certains la présence de contenu litigieux. Alors que certains&lt;br /&gt;robots ont tout intérêt à signaler leur visite, les robots des moteurs de recherche notamment, d&amp;#8217;autres chercheront à être plus discrets.&lt;/p&gt;
&lt;p&gt;On décrit l&amp;#8217;indexation des pages par les robots en deux phases. La première est couramment appelée &lt;em&gt;crawling&lt;/em&gt;, elle correspond au parcours du web le plus largement possible. La seconde phase est l&amp;#8217;indexation du document, c&amp;#8217;est à dire l&amp;#8217;analyse du contenu. À partir de ce principe simple, il est possible de créer des robots ayant des applications particulièrement variées.&lt;/p&gt;
&lt;p&gt;Pour indexer correctement un document, il faut choisir les éléments porteurs de sens. L&amp;#8217;analyse des fichiers comme les images, les applets Java ou les animations flash ne sera pas traitée ici car elle nécessite l&amp;#8217;utilisation d&amp;#8217;algorithmes complexes. On se limitera également à l&amp;#8217;analyse d&amp;#8217;une page HTML, mais le principe reste le même pour des documents comme les PDF, OpenDocument (format utilisé par OpenOffice) ou &lt;em&gt;OpenXML&lt;/em&gt; (format apparu avec Microsoft Office 2007).&lt;/p&gt;
&lt;p&gt;Certains éléments de la page n&amp;#8217;ont aucune utilité pour un robot, il faut donc être capable de sélectionner ceux qui seront porteurs de contenu pour gagner en pertinence. On peut lister les principales balises HTML utiles. Les éléments d&amp;#8217;en-tête et &lt;em&gt;meta&lt;/em&gt;&amp;#160;: ils contiennent des informations techniques ou sémantiques sur la page web fournies par le créateur de la page. Ils peuvent contenir des informations pertinentes, mais sont aussi utilisés de manière détournée pour &lt;em&gt;spammer&lt;/em&gt; les robots, c&amp;#8217;est pourquoi les moteurs de recherche y accordent de moins en moins d&amp;#8217;importance. On pourra tout de même s&amp;#8217;y intéresser car ils contiennent généralement quelques informations utiles.&lt;/p&gt;
&lt;p&gt;La balise &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; est particulièrement utilisée par les moteurs de recherche, c&amp;#8217;est pourquoi aujourd&amp;#8217;hui elle contient généralement le titre de la page mais aussi des mots clés précieux et pertinents sur le contenu. Les balises &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; à &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt; sont les titres de section. Ils ont le même intérêt que le titre de la page&amp;#160;: ils donnent généralement des mots clés pertinents pour identifier le sujet du contenu qui le suit.&lt;/p&gt;
&lt;p&gt;Les ancres et liens hypertextes &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; sont essentiels pour plusieurs raisons. Ils permettent d&amp;#8217;établir une carte du web, utilisée pour le &lt;em&gt;crawling&lt;/em&gt;, mais aussi pour évaluer la pertinence de la page dans le cadre étudié. Par exemple, le &lt;em&gt;pagerank&lt;/em&gt; de Google consiste à attribuer une notre de pertinence en fonction du nombre de pages qui lient celle étudiée et le pagerank de celles-ci. Les emphases, telles que &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; ou &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; peuvent permettre de mettre en valeur un mot ou une phrase particulièrement pertinente, mais leur intérêt reste relativement limité.&lt;/p&gt;
&lt;p&gt;Par ailleurs, il faut également pouvoir détecter les commentaires HTML pour les ignorer&amp;#160;: ils n&amp;#8217;apportent pas de contenu pour la page puisqu&amp;#8217;ils ne sont pas affichés, il n&amp;#8217;est donc pas nécessaire d&amp;#8217;en tenir compte pour indexer une page. On peut aussi lister un certains nombres d&amp;#8217;attributs de balises HTML qu&amp;#8217;il faut prendre en compte pour créer notre robot.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;L&amp;#8217;attribut &lt;code&gt;href&lt;/code&gt; contient l&amp;#8217;adresse d&amp;#8217;un lien vers une page depuis la page que nous analysons,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;src&lt;/code&gt; contient l&amp;#8217;adresse d&amp;#8217;un document inclus dans la page (une image ou un fichier javascript par exemple),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;title&lt;/code&gt; est généralement utilisé pour commenter une image ou un lien,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alt&lt;/code&gt; contient du texte alternatif affiché à la place d&amp;#8217;une image quand cela est impossible, comme il nous est impossible d&amp;#8217;analyser une image, cet attribut doit être utilisé pour ne pas manquer d&amp;#8217;informations,&lt;/li&gt;
&lt;li&gt;les&amp;nbsp; attributs &lt;code&gt;rel&lt;/code&gt; et &lt;code&gt;rev&lt;/code&gt; servent&amp;nbsp; à préciser&amp;nbsp; le&amp;nbsp; comportement&amp;nbsp; à&amp;nbsp; avoir&amp;nbsp; pour&amp;nbsp; suivre les&amp;nbsp; références&amp;nbsp; avant&amp;nbsp; et&amp;nbsp; arrière&amp;nbsp; de&amp;nbsp; la&amp;nbsp; page (&lt;code&gt;href&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Même si nous n&amp;#8217;essayerons pas de développer cette fonctionnalité, on peut envisager d&amp;#8217;introduire un système de pondération permettant de valoriser différemment le contenu des différents types de balises, en intégrant par exemple un coefficient de 1 pour l&amp;#8217;ensemble du contenu, de 10 pour l&amp;#8217;ensemble des mots clés du titre &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; et 3 points pour les emphases comme &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; ou &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt;. Cette idée permettrait d&amp;#8217;améliorer la qualité de l&amp;#8217;analyse, mais rendrait l&amp;#8217;indexation probablement beaucoup plus gourmande en mémoire.&lt;/p&gt;
&lt;h3&gt;Développer notre robot&lt;/h3&gt;
&lt;p&gt;Maintenant que nous avons fixé les éléments sur lesquels notre robot doit porter son attention, nous pouvons passer à son développement. PHP permet d&amp;#8217;ouvrir certains fichiers sur des serveurs distant grâce à l&amp;#8217;implémentation de certains protocoles, notamment HTTP et FTP. Cependant, pour que ceci soit possible, il faut que la directive &lt;code&gt;allow_url_fopen&lt;/code&gt; soit activée dans le fichier de configuration &lt;code&gt;php.ini&lt;/code&gt;, sachant qu&amp;#8217;il est impossible de l&amp;#8217;activer dynamiquement avec la fonction &lt;code&gt;ini_set()&lt;/code&gt;pour des raisons de sécurité.&lt;/p&gt;
&lt;p&gt;Nous pouvons donc simplement appeler notre fichier en utilisant &lt;code&gt;file_get_contents($url);&lt;/code&gt;. Reportez vous au constructeur (&lt;code&gt;__construct()&lt;/code&gt;, du code source) de la classe &lt;code&gt;spider&lt;/code&gt; pour en savoir plus. Il serait judicieux de vérifier si le fichier téléchargé est bien un document HTML, voire même effectuer ce test avant&amp;nbsp; l&amp;#8217;appel à &lt;code&gt;file_get_contents()&lt;/code&gt;, mais ce test n&amp;#8217;est pas toujours évident à réaliser, nous effectuerons donc cette tâche pendant l&amp;#8217;analyse du fichier.&lt;/p&gt;
&lt;p&gt;On commencera par supprimer les commentaires puis séparer l&amp;#8217;entête du contenu (le &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; du &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;) pour limiter le domaine de recherche des expressions, afin d&amp;#8217;économiser un peu de temps d&amp;#8217;exécution et de ressources. On utilisera plusieurs expressions régulières&lt;br /&gt;dans cet article, elles fonctionnent dans un cas standard mais probablement moins bien quand le code est mal conçu, c&amp;#8217;est à vous de les adapter aux usages rencontrés, ce qui constitue probablement le principal défi posé par le développement d&amp;#8217;un robot de ce type. Idéalement, si toutes les pages analysées étaient bien conçues, nous aurions pu utiliser l&amp;#8217;implémentation en PHP de l&amp;#8217;API DOM, rendant&lt;br /&gt;l&amp;#8217;analyse moins hasardeuse et plus commode à développer.&lt;/p&gt;
&lt;p&gt;Pour supprimer les commentaires, on utilisera l&amp;#8217;expression régulière PERL &lt;code&gt;`&amp;lt;!--(?:(?:\s|.)*?)--&amp;gt;`im&lt;/code&gt;. Elle n&amp;#8217;est peut-être pas idéale mais n&amp;#8217;est pas très lourde. Voici son fonctionnement&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Les caractères &lt;code&gt;`&lt;/code&gt; délimitent la chaîne recherchée,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;i&lt;/code&gt; est un modificateur qui indique à PHP que la recherche est insensible à la casse,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;m&lt;/code&gt; est un second modificateur permettant de faire une recherche sur plusieurs lignes,&lt;/li&gt;
&lt;li&gt;une assertion (entre parenthèses) est définie comme «non-capturante» par les caractères &lt;code&gt;?:&lt;/code&gt;, par souci d&amp;#8217;économie,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\s|.&lt;/code&gt; permet de choisir n&amp;#8217;importe quel caractère (&lt;code&gt;.&lt;/code&gt;) ou un caractère blanc (&lt;code&gt;\s&lt;/code&gt;, espace, retour à la ligne, etc),&lt;/li&gt;
&lt;li&gt;enfin, le quantificateur &lt;code&gt;*&lt;/code&gt; permet de sélectionner ce motif zéro, une ou plusieurs fois, il est suivi de &lt;code&gt;?&lt;/code&gt; qui rend ce quantificateur non-gourmand, il capturera donc la chaîne la plus courte possible qui satisfait le motif, et s&amp;#8217;arrête donc avant le premier motif &lt;code&gt;--&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On remplace le motif précédant par une chaîne vide de cette façon&amp;#160;: &lt;code&gt;preg_replace('`&amp;lt;!--(?:(?:\s|.)*?)--&amp;gt;`im', '', $contenu);&lt;/code&gt;. Les autres motifs utiliseront généralement une syntaxe similaire, c&amp;#8217;est pourquoi nous ne détaillerons que les éléments variants. Pour obtenir séparément le contenu de l&amp;#8217;entête, on utilise cette expression régulière&amp;#160;: &lt;code&gt;`&amp;lt;body(?:[^&amp;gt;]*)?&amp;gt;((?:\s|.)*?)&amp;lt;/body&amp;gt;`im&lt;/code&gt;, qui ne change pas beaucoup de la précédente&amp;#160;: on ajoute la prise en charge des différents attributs possibles de la balise &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; grâce au motif &lt;code&gt;(?: [^&amp;gt;]*)?&lt;/code&gt;, ce qui correspond à un nombre quelconque de caractères différents du &lt;code&gt;&amp;gt; ([^&amp;gt;]*)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
On peut maintenant analyser les méta-tags et vérifier le type de fichier que nous analysons. On retiendra deux types mime&amp;#160;: &lt;code&gt;text/htmltext/xhtml+xml&lt;/code&gt;, même si ce dernier est peu utilisé car les navigateurs trop anciens ne le reconnaissent pas. Pour analyser l&amp;#8217;ensemble des métas, on utilise la fonction &lt;code&gt;preg_match_all()&lt;/code&gt; et le motif &lt;code&gt;`&amp;lt;meta (?:http-equiv|name)=&quot;(.+?)&quot; +content=&quot;(.+?)&quot;(?:/)?&amp;gt;`im&lt;/code&gt; qui n&amp;#8217;apporte rien de nouveau dans sa syntaxe, sauf l&amp;#8217;ajout de l&amp;#8217;éventuel &lt;code&gt;/&lt;/code&gt; présent en XHTML. Il est maintenant possible d&amp;#8217;analyser le contenu. Les balises comme &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h[1-6]&amp;gt;&lt;/code&gt;, et &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; utilisent des expressions régulières presque identiques, c&amp;#8217;est pourquoi je ne détaillerai que l&amp;#8217;analyse des paragraphes &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;. Le contenu de la page étant placé dans le corps, la recherche est limitée à notre section &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;. On utilisera une expression régulière basée sur la même syntaxe que les précédentes&amp;#160;: &lt;code&gt;`&amp;lt;p(?: [^&amp;gt;]*)?&amp;gt;((?:\s|.)*?)?&amp;lt;/p&amp;gt;`im&lt;/code&gt;, c&amp;#8217;est pourquoi je ne la détaillerai pas non plus. Après avoir capturé le contenu des paragraphes, nous pouvons le débarrasser des balises HTML avec la fonction &lt;code&gt;strip_tags()&lt;/code&gt; pour compter les caractères avec &lt;code&gt;strlen()&lt;/code&gt; et les mots (c&amp;#8217;est à dire chaque suite de caractères entourée d&amp;#8217;espaces) avec &lt;code&gt;sizeof(explode(' ', $chaine))&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;analyse des liens et des images utilise à nouveau les même filons, comme présenté dans la fonction &lt;code&gt;Parse()&lt;/code&gt; du code source de la classe, vous constaterez que le code est relativement répétitif. L&amp;#8217;analyse des liens permet de dresser la carte des pages accessibles depuis la page étudiée, c&amp;#8217;est pourquoi elle est importante pour la suite (l&amp;#8217;étape de &lt;em&gt;crawling&lt;/em&gt;). Les liens peuvent être indiqués de manière relative dans la page, il faut donc que nous les modifions pour obtenir l&amp;#8217;adresse absolue de chaque lien sur la page. La première étape est de vérifier si on trouve un schéma d&amp;#8217;adresse tel que &lt;code&gt;http://&lt;/code&gt; (indiquant qu&amp;#8217;elle est exprimée de manière absolue) en début de chaîne, si il est absent, l&amp;#8217;adresse doit être complétée. Sinon, on remplace une éventuelle chaîne &lt;code&gt;./&lt;/code&gt; par le complément.&lt;/p&gt;
&lt;p&gt;On devine généralement le complément grâce à l&amp;#8217;adresse de la page courante, mais il peut arriver que les liens soient définis relativement à une autre adresse, définie par la balise &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt;. Vous pouvez vérifier en détail comment sont analysées les liens dans la fonction &lt;code&gt;Link()&lt;/code&gt; et comment est devinée la racine des liens avec la fonction &lt;code&gt;Root()&lt;/code&gt; de la classe. Une fois notre classe &lt;code&gt;Spider&lt;/code&gt; terminée, nous pouvons ajouter une fonction statique qui permet de lancer les opérations de crawling et d&amp;#8217;analyse (appelée &lt;code&gt;Analyse()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.martiusweb.net/public/phpsolutions/spider.phps&quot;&gt;Code source de la classe Spiders&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;Apprivoiser les robots et les moteurs de recherche sur son site&lt;/h3&gt;
&lt;p&gt;La plupart des robots des moteurs de recherche visitent votre site en s&amp;#8217;annonçant, il peut donc être pratique de les détecter pour par exemple, les compter séparément des visiteurs dans les statistiques. Commençons par dresser une liste (non exhaustive) des principaux robots connus. Googlebot, le principal robot de Google visite le web très régulièrement en mode Fresh Bot, il peut faire plusieurs passages sur une page par jour. Le Fresh Bot analyse le texte et non la structure, tandis que le Deep Bot visite une page plus rarement mais l&amp;#8217;analyse, comme son nom l&amp;#8217;indique, plus en profondeur.&lt;/p&gt;
&lt;p&gt;Le robot Slurp d&amp;#8217;inktomi, racheté par Yahoo! fonctionne d&amp;#8217;une manière assez similaire à Googlebot, mais ne classe pas pour autant les pages de la même manière. Par ailleurs le crawling semble moins régulier, mais généralement assez profond. Le robot de MSN Live est un peu moins célèbre, mais possède quelques options intéressantes, comme la possibilité, depuis peu, de lui conseiller la fréquence des visites la plus pertinente pour indexer vos pages (liée à la fréquence des mises à jour).&lt;/p&gt;
&lt;p&gt;Ces robots peuvent analyser une page en profondeur grâce aux balises HTML et leur sens, c&amp;#8217;est pourquoi les respecter vous permet d&amp;#8217;optimiser intelligemment vos pages pour un meilleur référencement. Il est temps de dire définitivement adieu à la mise en page basée sur les tableaux.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;art du référencement et de la SEO (pour Search Engine Optimization) est assez complexe mais puissant, et il impose de suivre quelques règles dont certains sont devenus spécialistes. La règle absolue, c&amp;#8217;est la qualité du contenu&amp;#160;: plus il est intéressant, plus votre site aura de chances de devenir populaire. Les artifices techniques ne permettront pas à eux seuls une bonne visibilité sur internet, mais ils ne sont pas non plus négligeables. Les robots ne parcourent pas toujours toute la page, stratégiquement, placer les liens en début de page et au sein du contenu, sur des mots clés choisis avec soin, valorisera le référencement des pages cibles. Par exemple, lorsque vous publiez un article, n&amp;#8217;hésitez pas à faire des liens vers d&amp;#8217;autres pages sur le même sujet, car le robot pourra l&amp;#8217;étudier avec le contenu autour de ce lien pour multiplier les mots clés. Par ailleurs, remplissez aussi les attributs title des liens avec d&amp;#8217;autres mots clés, vous multiplierez ainsi vos chances d&amp;#8217;apparaître dans des listes de résultats. Par ailleurs, des organismes travaillent sur des nouvelles normes et technologies pour qu&amp;#8217;un document numérique soit le plus efficacement compréhensible par les systèmes informatiques.&lt;/p&gt;
&lt;p&gt;Ces technologies pourraient permettre d&amp;#8217;indexer efficacement un maximum de pages, elles servent aujourd&amp;#8217;hui certaines bibliothèques et archives (comme la banque de données de l&amp;#8217;organisation mondiale de la santé). L&amp;#8217;une des normes les plus prometteuses est probablement&amp;nbsp; RDF (pour Resource Description Framework), appliquée notamment à la syntaxe XML. Elle permet de décrire intelligemment une grande variété de contenu comme des ressources web et leurs métadonnées (données à propos d&amp;#8217;autres données). Vous pouvez commencer à travailler avec ces technologies dans vos documents XML, car des robots d&amp;#8217;indexation de fils XML (comme les flux RSS et ATOM) apparaissent depuis quelques années.&lt;/p&gt;
&lt;p&gt;Le projet Dublin Core, avec l&amp;#8217;utilisation du couple XML/RDF permet de décrire 15 propriétés sur un document numérique, comme le titre, la description, le format ou l&amp;#8217;auteur. Il permet donc de mettre une certaine ressource numérique en lien avec d&amp;#8217;autres ressources. Dans une page HTML, il est possible d&amp;#8217;introduire les métadonnées Dublin Core à l&amp;#8217;aide de la balise meta, comme présenté ci-dessous. Vous aurez plus de détails sur cette syntaxe sur le site officiel du projet Dublin Core&amp;#160;: http://dublincore.org/documents/dcq-html/.&lt;/p&gt;
&lt;pre class=&quot;html sourcecode html&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Emeta.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;DC.Title&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Titre de document&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Pour en savoir plus sur les métadonnées et leur utilisation, rendez vous sur la page &lt;a hreflang=&quot;en&quot; href=&quot;http://peccatte.karefil.com/software/metadata.htm&quot;&gt;http://peccatte.karefil.com/software/metadata.htm&lt;/a&gt; qui vous renseignera sur un bon nombre d&amp;#8217;initiatives lancées ces dernières années.&lt;/p&gt;
&lt;p&gt;Il est important aussi de faire un point sur le comportement des robots vis-à-vis du contenu binaire, comme les images ou les animations Flash. Bien que Google étudie une manière d&amp;#8217;analyser le contenu direct des images dans ses laboratoires, aucun moteur de recherche n&amp;#8217;est actuellement capable de référencer directement une illustration. Dublin Core par exemple, pourrait palier à ce soucis, mais son application en ligne n&amp;#8217;est pas vraiment développée. Par ailleurs, d&amp;#8217;autres architectures de métadonnées comme EXIF permettent d&amp;#8217;inclure des tags ou des détails sur l&amp;#8217;image, mais celle-ci n&amp;#8217;est pas réellement standardisée et n&amp;#8217;est donc pas plus utilisée sur le web.&lt;/p&gt;
&lt;p&gt;On peut faire une petite exception pour les photographies prises avec un appareil numérique qui contiennent des informations sur la date de prise de vue et le type d&amp;#8217;appareil, mais généralement, les logiciels de retouche d&amp;#8217;image font disparaître ces informations, on les trouve donc vraiment peu sur Internet. La meilleure manière actuellement pour référencer une image est de placer des mots clés dans le nom du fichier, et en renseignant les attributs &lt;code&gt;title&lt;/code&gt; et &lt;code&gt;alt&lt;/code&gt; des balises HTML &lt;code&gt;img&lt;/code&gt;. Par ailleurs, les robots utilisent souvent les mots clés trouvés dans le texte entourant l&amp;#8217;image, quelques lignes avant et après la balise &lt;code&gt;img&lt;/code&gt;, les robots ne s&amp;#8217;occupent pas de la mise en forme réalisée grâce aux CSS.&lt;/p&gt;
&lt;p&gt;Le référencement des animations Flash est lui aussi problématique, en fonction de son utilisation. Un site entièrement basé sur une animation (schématiquement un nombre minimal de pages HTML avec une animation principale dynamique) sera presque impossible à référencer correctement. Si l&amp;#8217;unité du site reste la page, une utilisation, même intensive, de Flash n&amp;#8217;est plus vraiment un problème, et des solutions pour une intégration valide selon les normes du W3C et accessible (pour les victimes d&amp;#8217;un handicap et les robots) on été trouvées.&lt;/p&gt;
&lt;p&gt;Le code suivant présente la solution la plus facile et pratique, son inconvénient majeur est la perte de la détection automatique de la version du lecteur flash minimum requise.&lt;/p&gt;
&lt;pre class=&quot;html sourcecode html&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eobject.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;object&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;application/x-shockwave-flash&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;animation.swf&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Eparam.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;param&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;animation.swf&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;movie&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Ep%26amp%3Bgt%3CSEMI%3E.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;Contenu alternatif.&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fp%26amp%3Bgt%3CSEMI%3E.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3E%2Fobject%26amp%3Bgt%3CSEMI%3E.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/object&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;D&amp;#8217;autres solutions sont proposées sur l&amp;#8217;excellent site Web Rank Info&amp;#160;: &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.webrankinfo.com/actualites/200705-referencement-flash.htm&quot;&gt;http://www.webrankinfo.com/actualites/200705-referencement-flash.htm&lt;/a&gt;, notamment une technique très à la mode le Flash satay, où un fichier flash fait office de contrôleur frontal pour toutes les autres animations, chargées en fonction des paramètres passés. Cette technique est également applicable aux applets Java, par exemple.&lt;/p&gt;
&lt;p&gt;Enfin, une dernière problématique qu&amp;#8217;il convient d&amp;#8217;étudier concerne le référencement des sites internet intégrant la technologie Ajax ou d&amp;#8217;autres fonctionnant avec Javascript. En effet, du contenu rendu disponible uniquement par un appel Javascript est rarement lu par un robot, bien qu&amp;#8217;il semble que certains (Googlebot notamment) soient capables d&amp;#8217;interpréter certaines fonctions Javascript basiques. Le meilleur moyen de rendre le contenu d&amp;#8217;une page facile à référencer est de suivre les recommandations liées à l&amp;#8217;accessibilité des pages dynamiques, notamment proposer une alternative plus classique pour obtenir le contenu.&lt;/p&gt;
&lt;h3&gt;Identifier et gérer le passage d&amp;#8217;un robot&lt;/h3&gt;
&lt;p&gt;Les robots d&amp;#8217;indexation des moteurs de recherche peuvent être identifiés grâce au client qu&amp;#8217;ils annoncent utiliser ou leurs adresses. Ces informations sont disponibles dans les variables &lt;code&gt;$_SERVER['HTTP_USER_AGENT']&lt;/code&gt; ou &lt;code&gt;$_SERVER['REMOTE_ADDR']&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Googlebot se présentera par l&amp;#8217;une de ces chaînes&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;Googlebot/2.1 (+http://www.google.com/bot.html)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mozilla/5.0 (compatible; Googlebot/2.1;+http://www.google.com/bot.html)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Googlebot-Image/1.0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;et sera connu grâce à une adresse au format &lt;code&gt;crawl*.googlebot.com&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Slurp, d&amp;#8217;inktomi et Yahoo! peut être identifié par ces chaînes User-Agent&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;Mozilla/5.0 (compatible; Yahoo! Slurp;http://help.yahoo.com/help/us/ysearch/slurp)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;et l&amp;#8217;adresse sera au format &lt;code&gt;crawl.yahoo.net&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Le troisième robot le plus connu est le robot utilisé par MSN&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;msnbot/1.* (+http://search.msn.com/msnbot.htm)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mozilla/4.0 (compatible; MSIE 4.01; Windows NT; MSN Mobile Proxy)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
Les principaux hôtes utilisés sont &lt;code&gt;msnbot*.search.msn.com&lt;/code&gt; ou &lt;code&gt;livebot-*.search.live.com&lt;/code&gt;.&lt;br /&gt;&lt;p&gt;Vous pouvez obtenir plus de détails et références sur les autres robots d&amp;#8217;indexation, leurs &lt;em&gt;User-Agent&lt;/em&gt; ou leurs adresses sur ces pages&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.robots.darkseoteam.com/&quot;&gt;http://www.robots.darkseoteam.com/&lt;/a&gt; qui est une excellente référence informative, bien que tous les conseils ne soient pas à appliquer,&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;&lt;li&gt;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.actulab.com/identification-des-robots.php&quot;&gt;http://www.actulab.com/identification-des-robots.php&lt;/a&gt; qui propose une liste assez complète, bien qu&amp;#8217;un peu datée des hôtes et &lt;em&gt;User-Agent&lt;/em&gt; des principaux robots. qui est une excellente référence informative, bien que tous les conseils ne soient pas à appliquer,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;L&amp;#8217;identification des robots peut vous permettre d&amp;#8217;améliorer le comptage de vos visiteurs et d&amp;#8217;optimiser la fréquence de mise à jour de vos pages (les robots aiment les pages mises à jour).&lt;/p&gt;
&lt;p&gt;Vous pouvez également demander à un robot de ne pas indexer certaines parties de votre site internet en plaçant à la racine d&amp;#8217;un répertoire un fichier &lt;code&gt;robots.txt&lt;/code&gt; contenant les règles &lt;code&gt;User-Agent&lt;/code&gt; et &lt;code&gt;Disallow&lt;/code&gt;, comme ceci&amp;#160;:&lt;/p&gt;
&lt;pre&gt;User-agent: * # commentaire : tous les robots&lt;br /&gt;Disallow: /cgi-bin/&lt;br /&gt;Disallow: /perso/&lt;br /&gt;Disallow: /entravaux/&lt;br /&gt;Disallow: /abonnes/prix.html&lt;/pre&gt;&lt;p&gt;La règle &lt;code&gt;Allow&lt;/code&gt; est comprise par certains robots, mais n&amp;#8217;existe pas réellement et n&amp;#8217;est pas standardisée, il est donc déconseillé de l&amp;#8217;utiliser. La règle &lt;code&gt;User-Agent&lt;/code&gt; prend une valeur différente par robot (par exemple &lt;code&gt;msnbot&lt;/code&gt;, &lt;code&gt;googlebot&lt;/code&gt;) ou la valeur &lt;code&gt;*&lt;/code&gt; pour concerner tous les robots. La règle &lt;code&gt;Disallow&lt;/code&gt; précise quelles ressources ne doivent pas être indexées. Notez que vous ne devez pas laisser de ligne vide dans ce fichier, et qu&amp;#8217;il est possible d&amp;#8217;introduire des commentaires avec le symbole &lt;code&gt;#&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Vous pouvez également indiquer d&amp;#8217;autres règles de conduites au robots dans les balises HTML &lt;code&gt;meta,&lt;/code&gt; en utilisant cette syntaxe&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;html sourcecode html&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://december.com/html/4/element/%26amp%3Blt%3CSEMI%3Emeta.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;meta&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;robots&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;attribut1,attribut2&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;où &lt;code&gt;attribut1&lt;/code&gt;, peut prendre la valeur &lt;code&gt;index&lt;/code&gt; (autorise l&amp;#8217;indexation) ou &lt;code&gt;noindex&lt;/code&gt; (pour l&amp;#8217;interdire), et &lt;code&gt;attribut2&lt;/code&gt; peut prendre la valeur &lt;code&gt;follow&lt;/code&gt;, pour que le robot suive les liens contenus dans la page et &lt;code&gt;nofollow&lt;/code&gt; pour lui demander de ne pas suivre les liens de la page. Ce comportement peut également être décidé lien par lien grâce à l&amp;#8217;attribut &lt;code&gt;rel=&quot;nofollow&quot;&lt;/code&gt; de la balise HTML &lt;code&gt;a&lt;/code&gt;. Par défaut, un robot appliquera logiquement les règles &lt;code&gt;index&lt;/code&gt; et &lt;code&gt;follow&lt;/code&gt;. Par ailleurs, les robots peuvent également faire le choix de ne pas tenir compte de ces mesures (ce peut être le cas d&amp;#8217;un robot de contrôle cherchant à être discret ou d&amp;#8217;un renifleur utilisée à des fins parfois litigieuses), elles ne permettent donc pas rendre du contenu invisible sur internet.&lt;/p&gt;
&lt;h3&gt;Limites et dangers des techniques de Black Hat&lt;/h3&gt;
&lt;p&gt;Les techniques dites de &lt;em&gt;Black Hat&lt;/em&gt; sont des techniques permettant de modifier l&amp;#8217;analyse d&amp;#8217;une page en détournant le comportement d&amp;#8217;un robot. Ces techniques peuvent avoir différentes natures&amp;#160;: insérer dans son code des mots clés rendus invisibles pour le visiteur par les CSS, ou retourner une page différente de la page publique quand le robot est détecté. D&amp;#8217;autres techniques beaucoup plus poussées existent, mais le but cet article n&amp;#8217;est pas de les détailler.&lt;/p&gt;
&lt;p&gt;Ces techniques sont dangereuses car elles peuvent très rapidement pénaliser le référencement plus que l&amp;#8217;améliorer. En effet, la plupart des moteurs de recherches sont capables de détecter ces techniques, même les plus poussées, et peuvent mettre les pages concernées ou le site en liste noire et le bannir définitivement de ses résultats.&lt;/p&gt;
&lt;h3&gt;Concevoir son terrain d&amp;#8217;accueil&lt;/h3&gt;
&lt;p&gt;Un terrain d&amp;#8217;accueil (ou page d&amp;#8217;atterrissage, &lt;em&gt;landing page&lt;/em&gt;) est une page (ou un élément de la page) qui apparaît quand un utilisateur accède au site internet depuis un moteur de recherche et qui contient généralement du contenu adapté à la requête du visiteur. Un terrain d&amp;#8217;accueil est particulièrement intéressant pour proposer du contenu qui pourrait intéresser le visiteur même si il n&amp;#8217;est pas n&amp;#8217;est pas arrivé sur une page correspondant à sa recherche.&lt;/p&gt;
&lt;p&gt;Un terrain d&amp;#8217;accueil efficace doit fonctionner avec plusieurs moteurs de recherche. Pour vérifier qu&amp;#8217;un utilisateur vient d&amp;#8217;un moteur de recherche, on utilise la variable &lt;code&gt;$_SERVER['HTTP_REFERER']&lt;/code&gt;. On vérifie alors si l&amp;#8217;adresse de la page d&amp;#8217;origine est l&amp;#8217;adresse d&amp;#8217;un moteur de recherche. Nous allons faire la vérification avec les trois principaux moteurs de recherche du marché&amp;#160;: Google, Yahoo! et MSN.&lt;/p&gt;
&lt;p&gt;Les adresses des pages de résultats de ces trois moteurs de recherche sont les suivantes&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;http://www.google.fr/search?hl=fr&amp;amp;q=mon+mot+cle&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http://www.google.fr/search?hl=fr&amp;amp;q=mon+mot+cle&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http://search.msn.fr/results.aspx?q=mon+mot+cle&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Elles peuvent admettre d&amp;#8217;autres paramètres qui ne sont pas intéressants, mais il sera nécessaire d&amp;#8217;en tenir compte dans notre analyse du &lt;em&gt;referer&lt;/em&gt;. On tiendra aussi compte de l&amp;#8217;extension du nom de domaine qui peut varier. Il reste à étudier les expressions régulières à créer d&amp;#8217;après ces adresses.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;`http: //www\.google\.[a-z\.]+/search?.*?&amp;amp;?q=([\w%:+]+?)(?:&amp;amp;|$)`i&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;`http://\w+\.search.yahoo.com /search?.*?&amp;amp;?p=([\w%:+]+?)(?:&amp;amp;|$)`i&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;`http://search.msn.fr/results.aspx?.*?&amp;amp;?q=([\w%:+]+?)(?:&amp;amp;|$)`i&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On utilise une fois de plus la fonction preg_match() pour tester si l&amp;#8217;adresse du referer est celle d&amp;#8217;un moteur connu et récupérer les mots clés tapés par l&amp;#8217;utilisateur grâce aux parenthèses capturantes, et urldecode() pour que ces mots clés soient exploitables.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'`http://www&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\.&lt;/span&gt;google&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\.&lt;/span&gt;[a-z&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\.&lt;/span&gt;]+/search?.*?&amp;amp;?q=([&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\w&lt;/span&gt;%:+]+)(?:&amp;amp;|$)`i'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'HTTP_REFERER'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;	&lt;span style=&quot;color: #ff0000&quot;&gt;$keywords&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/urldecode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;urldecode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'`http://&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\w&lt;/span&gt;+&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\.&lt;/span&gt;search.yahoo.com/search?.*?&amp;amp;?p=([&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\w&lt;/span&gt;%:+]+)(?:&amp;amp;|$)`i'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'HTTP_REFERER'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;       &lt;span style=&quot;color: #ff0000&quot;&gt;$keywords&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/urldecode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;urldecode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'`http://search.msn.fr/results.aspx?.*?&amp;amp;?q=([&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\w&lt;/span&gt;%:+]+)(?:&amp;amp;|$)`i'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'HTTP_REFERER'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;	&lt;span style=&quot;color: #ff0000&quot;&gt;$keywords&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/urldecode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;urldecode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$kw&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;	&lt;span style=&quot;color: #ff0000&quot;&gt;$keywords&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Avec ces mots clés, vous pourrez effectuer une recherche interne à votre site pour proposer d&amp;#8217;autres de vos pages susceptibles d&amp;#8217;intéresser le visiteur, mettre en valeur ces mots clés dans la page ou encore proposer d&amp;#8217;autres références pour l&amp;#8217;inciter à rester sur votre site.&lt;/p&gt;
&lt;p&gt;Les terrains d&amp;#8217;accueil permettent d&amp;#8217;améliorer le taux de rebond (ou taux de visite à une page) d&amp;#8217;un site internet, et donc de le faire découvrir plus en détail au visiteur.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Vous avez maintenant quelques pistes pour analyser vos pages et améliorer leur référencement. Cependant, gardez en tête que le succès de votre site sera principalement lié à son contenu aux efforts de communication que vous ferez. N&amp;#8217;hésitez pas à partir en quête d&amp;#8217;informations sur internet, la SEO est devenue une discipline très à la mode depuis quelques années.&lt;/p&gt;
&lt;br /&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/PHP-Solutions-%3A-Robots-d-indexation-et-r%C3%A9f%C3%A9rencement#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/PHP-Solutions-%3A-Robots-d-indexation-et-r%C3%A9f%C3%A9rencement#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/141</wfw:commentRss>
      </item>
    
  <item>
    <title>Aidez-nous à faire mieux ! Répondez à notre sondage !</title>
    <link>http://www.martiusweb.net/post/Aidez-nous-%C3%A0-faire-mieux-%21-R%C3%A9pondez-%C3%A0-notre-sondage-%21</link>
    <guid isPermaLink="false">urn:md5:4f4aa995ed0d10c44ec56c5789f7101b</guid>
    <pubDate>Sun, 01 Nov 2009 19:48:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Actualités de Martius Web</category>
            
    <description>&lt;p&gt;Un sondage (court, pas d&amp;#8217;inquiétudes) a été mis en place pour permettre à Martius Web de faire mieux. Y répondre ne prend que quelques minutes, et peut nous filer un vrai coup de main&amp;#160;! N&amp;#8217;hésitez pas à le transmettre si vous jugez ça bon &lt;img src=&quot;/themes/martiusweb/smilies/wink.png&quot; alt=&quot;;)&quot; class=&quot;smiley&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Merci&amp;#160;!&lt;/p&gt;    &lt;iframe src=&quot;http://spreadsheets.google.com/embeddedform?key=tgPDAYj2jZXpKT6G1mwR-Eg&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; frameborder=&quot;0&quot; height=&quot;600&quot; width=&quot;100%&quot;&gt;Chargement&amp;#8230;&lt;/iframe&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Chargement automatique de classes avancé avec PHP 5</title>
    <link>http://www.martiusweb.net/post/Chargement-automatique-de-classes-avanc%C3%A9-avec-PHP-5</link>
    <guid isPermaLink="false">urn:md5:3dc59b7ab26971f35e538c8d01a499d0</guid>
    <pubDate>Thu, 29 Oct 2009 16:04:00 +0100</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Programmation PHP</category>
        <category>autoload</category><category>développeur</category><category>namespaces</category><category>php</category><category>php 5.3</category><category>POO</category><category>programmation</category><category>SPL</category>    
    <description>&lt;p&gt;PHP 5 a introduit de nombreux nouveaux concepts intéressants, notamment le &lt;strong&gt;chargement automatique&lt;/strong&gt; des dépendances lors de l&amp;#8217;utilisation d&amp;#8217;une classe non définie. On utilise généralement à cette fin la fonction magique &lt;code&gt;__autoload()&lt;/code&gt;. Mais depuis PHP 5.1.2, une séries de fonctions issues de la &lt;strong&gt;SPL&lt;/strong&gt; (&lt;em&gt;Standard PHP Library&lt;/em&gt;) &lt;code&gt;spl_autoload_*()&lt;/code&gt; sont apparues.&lt;/p&gt;
&lt;p&gt;Cet ensemble de fonction permet de mettre en place une stratégie de chargement dynamique plus fin, et nous allons ici essayer de découvrir &lt;em&gt;pourquoi&lt;/em&gt; et &lt;em&gt;comment&lt;/em&gt;.&lt;/p&gt;    &lt;h3&gt;Autoloading simple&lt;/h3&gt;
&lt;p&gt;Avant de rentrer dans les détails violents, nous allons commencer par faire un petit rappel (ou tout du moins une introduction) sur la notion. Les développeurs qui ne sont pas vraiment familiers avec le langage ne seront pas perdus&amp;#160;: les mécanismes mis en place ici sont tout à fait accessibles.&lt;/p&gt;
&lt;p&gt;On donne généralement plusieurs noms à cette fonctionnalité apparue avec PHP 5&amp;#160;: autoloading, chargement dynamique (ou automatique) de classes, inclusion implicite, et j&amp;#8217;en passe. En fait, tous ces noms sont corrects&amp;#8230; en fonction de la manière dont vous l&amp;#8217;utiliserez. Disons qu&amp;#8217;à la base, l&amp;#8217;autoloading est arrivé pour faciliter la vie des développeurs dans la gestion des dépendances.&lt;/p&gt;
&lt;p&gt;Dans un projet où l&amp;#8217;orienté objet prend une place importante, on se retrouve souvent avec de nombreuses classes, elles-mêmes généralement réparties dans de nombreux fichiers (souvent une ou deux classes par fichier). Le développeur devait alors vérifier l&amp;#8217;existence d&amp;#8217;une classe avant de l&amp;#8217;utiliser&amp;#160;: il est nécessaire de demander à PHP d&amp;#8217;interpréter sa définition pour qu&amp;#8217;elle &amp;#8220;existe&amp;#8221;. On observait alors souvent une série de directives &lt;code&gt;include&lt;/code&gt; ou &lt;code&gt;require&lt;/code&gt; en tête de fichier, voire &lt;code&gt;include_once&lt;/code&gt; et &lt;code&gt;require_once&lt;/code&gt; pour éviter une inclusion multiple, causant une erreur fatale puisque PHP interdit la redéfinition d&amp;#8217;un symbole existant. C&amp;#8217;était un peu abstrait, mais j&amp;#8217;imagine que vous ne découvrez pas ces problèmes si vous prenez la peine de vous renseigner sur le chargement automatique.&lt;/p&gt;
&lt;p&gt;La fonction magique &lt;code&gt;__autoload()&lt;/code&gt; a donc été introduite pour supprimer ces nombreuses inclusions, dont la maintenance devient fastidieuse dès que l&amp;#8217;organisation des fichiers de l&amp;#8217;application change un peu. On dit que cette fonction est magique, pas seulement parce qu&amp;#8217;elle rend un grand service, mais aussi parce que PHP va être capable de l&amp;#8217;appeler tout seul au bon moment, sans l&amp;#8217;aide du développeur, afin d&amp;#8217;alléger l&amp;#8217;écriture du code. En fait, lorsque l&amp;#8217;interpréteur rencontrera un nom (ou symbole) de classe inconnu, il appellera implicitement cette fonction en passant ce nom en paramètre.&lt;/p&gt;
&lt;p&gt;À titre informatif, il est impossible de lancer une exception dans la fonction &lt;code&gt;__autoload()&lt;/code&gt; car elle est exécuté à un moment qui ne peut être défini à priori (lors de l&amp;#8217;interprétation du fichier ou de l&amp;#8217;exécution du code utilisant la classe, par exemple&amp;#160;?). Plusieurs solutions basées sur la &lt;a hreflang=&quot;en&quot; href=&quot;http://www.onphp5.com/article/61&quot;&gt;création dynamique d&amp;#8217;une classe&lt;/a&gt; à l&amp;#8217;aide de la fonction &lt;code&gt;eval()&lt;/code&gt; on été proposées. Je les trouve généralement inutiles et dangereuses.&lt;/p&gt;
&lt;p&gt;On peut imaginer une implémentation sommaire sous cette forme&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'CLASSES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/classes'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;a href=&quot;http://www.php.net/__autoload&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;__autoload&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Ouf, du code&amp;#160;! Ici, on fait en sorte que pour une classe &lt;code&gt;MyClass&lt;/code&gt;, PHP charge le fichier &lt;code&gt;myproject/classes/class.MyClass.php&lt;/code&gt;, qui devrait, le cas échéant, contenir la définition de &lt;code&gt;MyClass&lt;/code&gt;. C&amp;#8217;est bien, mais encore un peu light dès qu&amp;#8217;on cherche à décomposer l&amp;#8217;organisation des fichiers en plusieurs répertoires.&lt;/p&gt;
&lt;p&gt;On a alors plusieurs solutions&amp;#160;: on peut demander à PHP de parcourir l&amp;#8217;ensemble de nos répertoires pour trouver la classe, à l&amp;#8217;aide de différentes implémentations&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'CLASSES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/classes'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;a href=&quot;http://www.php.net/__autoload&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;__autoload&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$classes_dirs&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'core'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'tools'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'model'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'dblayer'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classes_dir&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$dir&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$classpath&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$dir&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/file_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classpath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$classpath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;On peut aussi faire encore pire&amp;#160;: parcourir les répertoires à la recherche du bon fichier et l&amp;#8217;inclure ensuite&amp;#160;! Ces méthodes, en plus d&amp;#8217;être hasardeuses, sont très couteuses en ressources&amp;#160;: on utilise une boucle et on réalise plusieurs opérations sur le système de fichier (qui font partie des opérations les plus lentes d&amp;#8217;un programme, à cause notamment du temps d&amp;#8217;accès au disque dur).&lt;/p&gt;
&lt;p&gt;Une méthode plus élégante serait d&amp;#8217;enregistrer dans un tableau la liste de chaque classe associé au fichier qui contient sa définition, on aurait alors, par exemple&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'MyClass'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'core/class.MyClass.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'MyModelClass'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'model/class.MyModelClass.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'EmailEasing'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'tools/class.EmailEasing.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;dans un fichier &lt;code&gt;autoloading.php&lt;/code&gt;, et une implémentation de la fonction &lt;code&gt;__autoload&lt;/code&gt; comme celle-ci&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'CLASSES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/classes'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;a href=&quot;http://www.php.net/__autoload&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;__autoload&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'autoloading.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;On fait un travail plus propre&amp;#160;: le fichier contenant la liste des dépendances est inclus une seule fois grâce au fait que la variable soit statique et on évite des recherches inutiles. D&amp;#8217;un autre côté, on perd une partie des avantages du chargement dynamique, puisque le développeur devra tout de même maintenir le fameux fichier de dépendances. Quand il n&amp;#8217;y en a que quelques unes, ça va, mais c&amp;#8217;est quand il y en a beaucoup&amp;#8230;&lt;/p&gt;
&lt;p&gt;De nombreuses solutions plus ou moins compliquées existent&amp;#160;: effectuer une recherche puis mettre en cache, créer un script qui générera le fichier de dépendances qu&amp;#8217;on appellera lors de la mise à jour du code, et plus exotique encore.&lt;/p&gt;
&lt;h3&gt;Un chargement dynamique natif avec &lt;code&gt;spl_autoload()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Depuis PHP 5.1.2, les développeurs nous simplifient un peu la vie et offrent une réponse toute prête au dilemme posé plus tôt. Chouette&amp;#160;!&lt;/p&gt;
&lt;p&gt;Si aucune fonction &lt;code&gt;__autoload()&lt;/code&gt; n&amp;#8217;est définie, alors PHP utilisera la function native &lt;code&gt;spl_autoload()&lt;/code&gt; par défaut à condition qu&amp;#8217;on lui demande&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Son comportement est assez simple et se base sur une stratégie bien connue avec &lt;code&gt;include&lt;/code&gt; et &lt;code&gt;require&lt;/code&gt;&amp;#160;: on cherche partout où la configuration dit de chercher, et on prend le premier trouvé. Pour ma fameuse &lt;code&gt;MyClass&lt;/code&gt;, &lt;code&gt;spl_autoload()&lt;/code&gt; va parcourir chaque répertoire définit dans la directive &lt;code&gt;include_path&lt;/code&gt; à la recherche d&amp;#8217;un fichier appelé &lt;code&gt;MyClass.php&lt;/code&gt; ou &lt;code&gt;MyClass.inc&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;On peut obtenir une solution proche de celle décrite dans le deuxième exemple avec deux avantages&amp;#160;: d&amp;#8217;une part l&amp;#8217;implémentation sera légèrement plus rapide et plus souple, d&amp;#8217;autre part, elle fera appel à des fonctions natives, donc écrites en C, et donc qui seront presque à tous les coups plus rapides que notre propre version de &lt;code&gt;__autoload()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Tout ceci est bien entendu paramétrable. Pour modifier la liste des répertoires parcourus, on peut modifier la valeur de la directive &lt;code&gt;include_path&lt;/code&gt; dans le &lt;code&gt;php.ini&lt;/code&gt;, ou utiliser le couple de fonctions &lt;code&gt;set_include_path()&lt;/code&gt; et &lt;code&gt;get_include_path()&lt;/code&gt;. Il est également possible d&amp;#8217;ajouter des extensions à la recherche grâce à &lt;code&gt;spl_autoload_extensions()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Pour reprendre notre second exemple, on pourra l&amp;#8217;implémenter ainsi&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'CLASSES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/classes'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_extensions&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_extensions&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.class.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/set_include_path&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;set_include_path&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/core'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;PATH_SEPARATOR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/tools'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;PATH_SEPARATOR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/model'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;PATH_SEPARATOR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/dblayer'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  PATH_SEPARATOR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;a href=&quot;http://www.php.net/get_include_path&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;get_include_path&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;On place nos répertoires en premier pour qu&amp;#8217;ils soient prioritaires, sans oublier d&amp;#8217;ajouter les valeurs déjà définies avec &lt;code&gt;get_include_path()&lt;/code&gt;. Par ailleurs, il est nécessaire de modifier légèrement notre convention de nommage des fichiers&amp;#160;: &lt;code&gt;class.MyClass.php&lt;/code&gt; devient nécessairement &lt;code&gt;MyClass.class.php&lt;/code&gt;. Finalement, tout ça n&amp;#8217;est pas très satisfaisant&amp;#160;: comme on l&amp;#8217;a évoqué tout à l&amp;#8217;heure, les opérations sur le système de fichier ne sont pas très amies avec l&amp;#8217;optimisation temporelle d&amp;#8217;un script.&lt;/p&gt;
&lt;p&gt;Avec des tests correspondant à votre situation, vous pourrez probablement choisir entre l&amp;#8217;implémentation suivante et celle proposée dans le troisième exemple.&lt;/p&gt;
&lt;h3&gt;Concurrence d&amp;#8217;autoloads&lt;/h3&gt;
&lt;p&gt;Sur un gros projet, vous allez parfois devoir manipuler plusieurs bibliothèques ou frameworks qui devront travailler en collaboration lors de l&amp;#8217;exécution d&amp;#8217;un script. Imaginez que chacune de ces bibliothèques possèdent leur propre implémentation de la fonction &lt;code&gt;__autoload()&lt;/code&gt;. Ce cas de figure ne se présentera pas puisque PHP ne supporte pas la surcharge de fonctions, et le seul résultat qu&amp;#8217;on pourra obtenir est une erreur fatale&amp;#8230;&lt;/p&gt;
&lt;p&gt;Grâce aux fonctions &lt;code&gt;spl_autoload_*()&lt;/code&gt;, il est possible de manipuler plusieurs implémentations de chargement dynamique sans collisions. On utilise alors les méthodes &lt;code&gt;spl_autoload_register()&lt;/code&gt; et éventuellement &lt;code&gt;spl_autoload_unregister()&lt;/code&gt;. Ces fonctions permettent de gérer une file de fonctions exécutées les unes après les autres jusqu&amp;#8217;à ce que le problème de dépendance soit résolu. Un petit exemple sera peut-être plus parlant&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; fantastic_framework_autoload&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/file_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fantasticframework/classes/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'fantasticframework/classes/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; helperslib_autoload&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/file_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'helpers/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'helpers/class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;a href=&quot;http://www.php.net/__autoload&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;__autoload&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'autoloading.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; CLASSES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$_autoload&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fantastic_framework_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'helperslib_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'__autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Ici, pour chaque dépendance non satisfaite, PHP exécutera chaque fonction une à une jusqu&amp;#8217;à ce que le problème soit résolu. Permettant ainsi de définir plusieurs stratégies différentes en fonction du contexte. L&amp;#8217;ordre d&amp;#8217;exécution est celui définit par l&amp;#8217;ordre d&amp;#8217;enregistrement des fonctions&amp;#160;: ici &lt;code&gt;fantastic_framework_autoload&lt;/code&gt;, &lt;code&gt;helperslib_autoload&lt;/code&gt; et enfin &lt;code&gt;__autoload&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Notez qu&amp;#8217;il est nécessaire d&amp;#8217;enregistrer manuellement &lt;code&gt;__autoload&lt;/code&gt;(), &lt;code&gt;spl_autoload_register&lt;/code&gt; remplace en effet le comportement par défaut de PHP. Il sera également nécessaire d&amp;#8217;enregistrer manuellement la fonction &lt;code&gt;spl_autoload()&lt;/code&gt; vue plus tôt si vous souhaitez l&amp;#8217;utiliser.&lt;/p&gt;
&lt;p&gt;Il est également important de noter qu&amp;#8217;ici, il est nécessaire que les différentes fonctions utilisées ne puissent pas retourner d&amp;#8217;erreur&amp;#160;: le test de l&amp;#8217;existence du fichier avant l&amp;#8217;inclusion est obligatoire, sinon PHP affichera une erreur (causant l&amp;#8217;arrêt du script avec &lt;code&gt;require&lt;/code&gt;).&lt;/p&gt;
&lt;h3&gt;Synchroniser le système de fichier et le nom des classes&lt;/h3&gt;
&lt;p&gt;Une méthode qui peut être explorée consiste à utiliser le nom de la classe à charger pour deviner l&amp;#8217;emplacement du fichier dans notre organisation. Ce cas de figure est particulièrement intéressant quand l&amp;#8217;organisation est découpée en modules.&lt;/p&gt;
&lt;p&gt;Par exemple, mon programme contient, entre autres, les classes suivantes&amp;#160;: &lt;code&gt;MyAppRequest&lt;/code&gt;, &lt;code&gt;MyAppContext&lt;/code&gt;, &lt;code&gt;MyAppConfig&lt;/code&gt;, &lt;code&gt;ViewTemplate&lt;/code&gt;, &lt;code&gt;ViewCache&lt;/code&gt;, &lt;code&gt;DbConnection&lt;/code&gt;, et pour finir, &lt;code&gt;EmailEasing&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Comme le projet a été réfléchi en amont et que ces noms correspondent à des conventions définies, tout ceci a un sens facilitant l&amp;#8217;organisation du code&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;le préfixe &lt;code&gt;MyApp&lt;/code&gt; correspond aux classes faisant partie du coeur de l&amp;#8217;application,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;View&lt;/code&gt; correspond aux classes composant la partie vue (moteur de templates, etc),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Db&lt;/code&gt; aux outils permettant de manipuler la base de données,&lt;/li&gt;
&lt;li&gt;et enfin le suffixe &lt;code&gt;Easing&lt;/code&gt; signifie que la classe correspond à une bibliothèque simplifiant certaines opérations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On peut alors facilement répartir ces classes dans des fichiers bien organisés&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;sources/core&lt;/code&gt;, par exemple, &lt;code&gt;MyAppRequest&lt;/code&gt; sera dans le fichier &lt;code&gt;sources/core/class.Request.php&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sources/view&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sources/dblayer&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sources/libs&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On peut alors proposer une implémentation efficace, fine et protégée contre la concurrence assez facilement&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'SOURCES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/sources'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp;* Autoload pour notre application.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp;* Attention, les noms de classes et de fichiers sont sensibles&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp;* à la casse.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;myapp_autoload&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; SOURCES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'MyApp'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'core/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'View'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'view/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Db'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'dblayer/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Easing'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'libs/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$file&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/substr&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;substr&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'myapp_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/function_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;function_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'__autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'__autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'spl_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h3&gt;PHP 5.3 et les namespaces pour simplifier tout ça&lt;/h3&gt;
&lt;p&gt;La dernière solution que je vais développer utilise une nouvelle notion introduite dans PHP 5.3. C&amp;#8217;est une version simplifiée de la précédente, et que j&amp;#8217;envisage d&amp;#8217;utiliser dans la plupart des projets en PHP 5.3 sur lesquels je travaillerais.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;utilisation des &lt;a hreflang=&quot;fr&quot; href=&quot;http://fr.php.net/manual/fr/language.namespaces.php&quot;&gt;namespaces&lt;/a&gt; (ou espaces de noms en français) permet d&amp;#8217;organiser logiquement les classes en modules, afin d&amp;#8217;éviter les collisions entre plusieurs classes portant le même nom. Par analogie, il est souvent intéressant de calquer l&amp;#8217;organisation des fichiers avec l&amp;#8217;organisation choisie pour les espaces de nom.&lt;/p&gt;
&lt;p&gt;Avec les espaces de nom, une classe possède un nom absolu sous la forme &lt;code&gt;namespace\subnamespace\MyClass&lt;/code&gt;. on aurait donc les classes et namespaces suivants&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;namespace &lt;code&gt;MyApp&lt;/code&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;MyApp\Request&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;MyApp\Config&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;MyApp\Context&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;namespace View
&lt;ul&gt;&lt;li&gt;&lt;code&gt;View\Template&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;View\Cache&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;namespace Db
&lt;ul&gt;&lt;li&gt;&lt;code&gt;Db\Connection&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;namespace Easing
&lt;ul&gt;&lt;li&gt;&lt;code&gt;Easing\Email&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Notre fonction de chargement automatique sera&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/define&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;define&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'SOURCES_DIR'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'myproject/sources'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;myapp_autoload&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Au passage, pensez à échapper le caractère \ !&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/explode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;explode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\\&lt;/span&gt;'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Remplacement des namespaces dont le répertoire ne concorde pas :&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'MyApp'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'core'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Db'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'dblayer'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Easing'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;==&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'libs'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; SOURCES_DIR&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$j&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/sizeof&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;sizeof&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$j&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;a href=&quot;http://www.php.net/strtolower&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strtolower&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'/'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'class.'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array_pop&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array_pop&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$classname&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'.php'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/file_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #b1b100;&quot;&gt;require&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$path&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'myapp_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/function_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;function_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'__autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'__autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;a href=&quot;http://www.php.net/spl_autoload_register&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;spl_autoload_register&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'spl_autoload'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Ici, on retiendra l&amp;#8217;organisation des fichiers suivante&amp;#160;: &lt;code&gt;myproject/sources/core/class.Request.php&lt;/code&gt;, &lt;code&gt;myproject/sources/view/class.Templates.php&lt;/code&gt;, etc. L&amp;#8217;utilisation du test sur l&amp;#8217;existance du fichier avec &lt;code&gt;file_exists()&lt;/code&gt; pourrait être évitée (et faire économiser du temps) si on s&amp;#8217;assure qu&amp;#8217;il n&amp;#8217;est pas nécessaire de définir d&amp;#8217;autre méthode de chargement automatique exécutée si celle-ci échoue, ou en inversant l&amp;#8217;ordre d&amp;#8217;exécution des différentes fonctions pour obtenir la plus efficace possible.&lt;/p&gt;
&lt;p&gt;En plus, il est possible que la fonction &lt;code&gt;myapp_autoload()&lt;/code&gt; ne soit plus modifiée, car si on souhaite créer un nouveau namespace et de nouvelles classes, on obtient automatiquement une correspondance, par exemple la classe &lt;code&gt;Cookies&lt;/code&gt; dans le namespace &lt;code&gt;Tools\Http&lt;/code&gt;, dont le nom absolu sera &lt;code&gt;Tools\Http\Cookies&lt;/code&gt; sera, par défaut, recherchée dans &lt;code&gt;myproject/sources/tools/http/class.Cookies.php&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;La fonctionnalité d&amp;#8217;auto-chargement de classes de PHP permet de simplifier la gestion des dépendances de plusieurs manières. Les opérations d&amp;#8217;inclusion implicites sont couteuses en temps et en mémoire, il est donc pertinent d&amp;#8217;envisager un moyen d&amp;#8217;optimiser ce mécanisme. D&amp;#8217;une manière générale, on évitera le plus possible les tests sur l&amp;#8217;organisation du système de fichier, qui prennent beaucoup de temps. Dans une moindre mesure, on peut préférer éviter de charger un tableau en mémoire et devoir rechercher une valeur dedans à chaque chargement, bien que l&amp;#8217;implémentation des tableaux associatifs en PHP offre des performances très satisfaisantes.&lt;/p&gt;
&lt;p&gt;
Enfin, l&amp;#8217;arrivée de nouvelles fonctionnalités avec PHP 5.3, dont les &lt;em&gt;namespaces&lt;/em&gt;, peuvent nettement simplifier tout ceci en adoptant une structure intelligente.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Chargement-automatique-de-classes-avanc%C3%A9-avec-PHP-5#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Chargement-automatique-de-classes-avanc%C3%A9-avec-PHP-5#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/136</wfw:commentRss>
      </item>
    
  <item>
    <title>C'est parti pour Martius Web version 2 (béta quand même !)</title>
    <link>http://www.martiusweb.net/post/Cest-parti-pour-Martius-Web-version-2-beta</link>
    <guid isPermaLink="false">urn:md5:433ccd0052cb8c23ce60708b6a7d496e</guid>
    <pubDate>Sat, 17 Oct 2009 00:41:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Actualités de Martius Web</category>
        <category>creative commons</category><category>nouveau</category>    
    <description>&lt;p&gt;C&amp;#8217;est le grand moment, nous somme le samedi 17 octobre, et j&amp;#8217;ai décidé,
là comme ça, de lancer Martius Web version 2&amp;#160;en &amp;#8220;béta&amp;#8221; publique.&lt;/p&gt;    &lt;h3&gt;Mais c&amp;#8217;est quoi&amp;#160;?&lt;/h3&gt;
&lt;p&gt;Peut-être, cher visiteur, arrives-tu ici pour la première fois, ou alors, tu t&amp;#8217;es déjà égaré sur ces pages, mais n&amp;#8217;a jamais très bien compris d&amp;#8217;où elles viennent et à qui elles sont destinées&amp;#160;! On va faire un petit récapitulatif&amp;#160;!&lt;/p&gt;
&lt;p&gt;Martius et Web sont deux mots&amp;#160;: &lt;em&gt;Martius&lt;/em&gt;, c&amp;#8217;est moi à l&amp;#8217;heure ou j&amp;#8217;écris ces lignes, je suis étudiant en ingénierie informatique à Lyon et auto-entrepreneur. &lt;em&gt;Web&lt;/em&gt; parce que j&amp;#8217;aime beaucoup le développement web et tout ce qui y touche, de près comme de loin&amp;#160;: langages, outils, design, et de la communication.&lt;/p&gt;
&lt;p&gt;Martius Web est à l&amp;#8217;origine un site perso sur lequel je voulais exposer quelques expérimentations que je fais depuis plusieurs années. Entre temps, j&amp;#8217;ai eu envie d&amp;#8217;écrire un cours sur le &lt;strong&gt;XHTML&lt;/strong&gt; et les &lt;strong&gt;CSS&lt;/strong&gt;. C&amp;#8217;est comme ça qu&amp;#8217;est né la version du site qui existait encore hier. Entre temps, c&amp;#8217;est devenu une usine à gaz que je ne mettais plus très régulièrement à jour&amp;#160;: ça commençait à dater&amp;#8230;&lt;/p&gt;
&lt;p&gt;Je suis revenu au racines et j&amp;#8217;ai commencé à travailler sur cette version, qui est avant-tout un endroit où je peux exposer des infos, des découvertes et des expérimentations que j&amp;#8217;ai pu réaliser. J&amp;#8217;ai ajouté quelques pages qui décrivent (un peu pompeusement) mon activité d&amp;#8217;auto-entrepreneur. Et voilà&amp;#160;!&lt;/p&gt;
&lt;h3&gt;C&amp;#8217;est au point&amp;#160;?&lt;/h3&gt;
&lt;p&gt;A vrai dire, oui et non&amp;#160;! C&amp;#8217;est une béta&amp;#160;: je ne l&amp;#8217;appelle pas comme ça parce que c&amp;#8217;est un super terme à la mode depuis que Google à relancé cette tendance pour ses services, mais bien parce que tout n&amp;#8217;est pas terminé&amp;#160;! Les tutos sont toujours incomplets, parfois mal relus, donc encore plus mal corrigés&amp;#8230; J&amp;#8217;attendais juste d&amp;#8217;avoir au moins autant de contenu pertinent que sur l&amp;#8217;ancienne version pour que ça devienne public.&lt;/p&gt;
&lt;h3&gt;C&amp;#8217;est pour quoi&amp;#160;?&lt;/h3&gt;
&lt;p&gt;J&amp;#8217;écris autant que possible sur le site quand je découvre un &lt;em&gt;truc&lt;/em&gt; qui me semble pertinent et à partager.&lt;/p&gt;
&lt;p&gt;Pensez juste à ça&amp;#160;: c&amp;#8217;est gratuit, soumis aux commentaires et sous licence creative commons BY-NC-SA, vous pouvez donc les lire, copier et partager à volonté, tant que vous respectez trois de mes défauts&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;je suis mégalo et je veux que vous rappeliez que je suis l&amp;#8217;auteur,&lt;/li&gt;
&lt;li&gt;je suis aussi assez mauvais quand on essaie de se faire de l&amp;#8217;argent sans que j&amp;#8217;en prenne part, donc tout usage commercial est interdit&amp;#160;!&lt;/li&gt;
&lt;li&gt;je suis aussi viral, et tout ce que vous prendrez sur ce site devra être incubé et éventuellement transmis en respectant ces termes de licence&amp;#160;!&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;On peut participer&amp;#160;?&lt;/h3&gt;
&lt;p&gt;Avec plaisir&amp;#160;! Si vous avez envie d&amp;#8217;écrire ici, envoyez-moi un mail pour qu&amp;#8217;on en discute, sinon, n&amp;#8217;hésitez pas à commenter, corriger et mettre à jour ce qui passe ici&amp;#160;!&lt;/p&gt;
&lt;h3&gt;Le mot de la fin&lt;/h3&gt;
&lt;p&gt;Pour finir ce nouveau début, je serais bref (enfin&amp;#160;!)&amp;#160;: bonne visite&amp;#160;! J&amp;#8217;espère que vous apprécierez&amp;#160;!&lt;/p&gt;
&lt;br /&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Cest-parti-pour-Martius-Web-version-2-beta#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Cest-parti-pour-Martius-Web-version-2-beta#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/134</wfw:commentRss>
      </item>
    
  <item>
    <title>Martius Web sur JeSuisUnAutoEntrepreneur.com !</title>
    <link>http://www.martiusweb.net/post/Martius-Web-sur-JeSuisUnAutoEntrepreneur.com-%21</link>
    <guid isPermaLink="false">urn:md5:1c8b26134fa6fa9dbcb61283979e6d9e</guid>
    <pubDate>Fri, 15 May 2009 17:13:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Actualités de Martius Web</category>
        <category>AE</category><category>auto-entrepreneur</category><category>interview</category>    
    <description>&lt;p&gt;Depuis quelques jours, vous trouverez sur le site internet &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.jesuisunautoentrepreneur.com&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;Je suis un auto-entrepreneur&lt;/a&gt; une interview au sujet de Martius Web et de mon statut d&amp;#8217;auto-entrepreneur&amp;#160;!&lt;/p&gt;    &lt;p&gt;Le site internet recense aujourd&amp;#8217;hui une dizaine de portraits d&amp;#8217;auto-entrepreneurs exérçant dans des domaines d&amp;#8217;activités variés. Si vous hésitez encore, ou que vous êtes à la recherche de retours d&amp;#8217;expériences, passez y faire un tour&amp;#160;! Le site propose également quelques informations sur l&amp;#8217;&lt;a hreflang=&quot;fr&quot; href=&quot;http://www.jesuisunautoentrepreneur.com/actualite/&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;actualité du statut&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Je pense que vous pouvez contacter &lt;a hreflang=&quot;fr&quot; onclick=&quot;window.open(this.href); return false;&quot; href=&quot;http://www.jesuisunautoentrepreneur.com/pour-nous-contacter&quot;&gt;Julien&lt;/a&gt; pour avoir plus d&amp;#8217;informations, ou vous faire tirer le portrait également&amp;#160;!&lt;/p&gt;
&lt;p&gt;
&lt;!-- Ct-Info --&gt;
&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Jesuisunautoentrepreneur.com
est un site qui s’adresse aux auto-entrepreneurs mais également à tous
ceux qui s’intéressent à ce statut et plus largement à la création
d’entreprise.&lt;/p&gt;
&lt;p&gt;Sur ce site, vous pourrez trouver de l’actualité concernant ce
statut mais vous aurez surtout la possibilité de voir des portraits
d’auto-entrepreneurs bien réels, qui viendront vous expliquer pourquoi
ils ont choisi ce statut et ce que cela leur apporte.&lt;/p&gt;
&lt;p&gt;Alors, si vous avez envie de créer votre propre activité mais vous
ne souhaitez pas pour autant créer une entreprise, ce site est sans
doute pour vous&amp;#160;!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Ah, et oui, bien sûr, voici &lt;a hreflang=&quot;fr&quot; onclick=&quot;window.open(this.href); return false;&quot; href=&quot;http://www.jesuisunautoentrepreneur.com/2009/05/14/martin-richard/&quot;&gt;le lien direct vers mon profil&lt;/a&gt;&amp;#160;!&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Martius-Web-sur-JeSuisUnAutoEntrepreneur.com-%21#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Martius-Web-sur-JeSuisUnAutoEntrepreneur.com-%21#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/44</wfw:commentRss>
      </item>
    
  <item>
    <title>Luxury Flat In Dijon</title>
    <link>http://www.martiusweb.net/post/Luxury-Flat-In-Dijon</link>
    <guid isPermaLink="false">urn:md5:67de13e6be533e8ed925a358eb0cc70f</guid>
    <pubDate>Fri, 15 May 2009 11:31:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Nos réalisations</category>
            
    <description>    &lt;p style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://www.luxuryflatindijon.fr&quot; onclick=&quot;window.open(this.href); return false;&quot; title=&quot;Visiter le site Luxuryflatindijon.fr&quot;&gt;&lt;img title=&quot;Luxury Flat In Dijon : Intégration XHTML/CSS + Développement d'une administration simplifiée&quot; alt=&quot;Capture d'écran du site internet Luxuryflatiundijon.fr&quot; src=&quot;http://www.martiusweb.net/public/realisations/luxuryflatindijon.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Luxury Flat In Dijon est une agence de location d&amp;#8217;appartements au cœur du centre ville. Nous nous somme chargé de l&amp;#8217;intégration du design réalisé avec Adobe Illustrator, et du développement d&amp;#8217;une solution d&amp;#8217;administration, à la fois plus simple à mettre en place et à utiliser qu&amp;#8217;un CMS proposant de nombreuses fonctionnalités inutiles.&lt;/p&gt;
&lt;p&gt;Par ailleurs, Martius Web a accompagné et conseillé l&amp;#8217;agence sur les méthodes d&amp;#8217;édition ou de référencement permettant de maintenir le site efficacement.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.luxuryflatindijon.fr&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;Visiter le site internet Luxury Flat In Dijon&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Luxury-Flat-In-Dijon#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Luxury-Flat-In-Dijon#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/43</wfw:commentRss>
      </item>
    
  <item>
    <title>PHP Solutions : Concevoir une application pour le Web avec Ajax</title>
    <link>http://www.martiusweb.net/post/PHP-Solutions-%3A-Concevoir-une-application-pour-le-Web-avec-Ajax</link>
    <guid isPermaLink="false">urn:md5:ae72aa9db8fad2c00a79500681557e67</guid>
    <pubDate>Fri, 01 May 2009 19:26:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Programmation PHP</category>
        <category>accessibilité</category><category>Ajax</category><category>bases</category><category>création de sites web</category><category>css</category><category>Javascript</category><category>php</category><category>xhtml</category><category>XML</category>    
    <description>&lt;p&gt;&lt;em&gt;Article paru dans le magazine &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.phpsolmag.org&quot;&gt;PHP Solutions&lt;/a&gt;&amp;nbsp;(Mai 2008). Attention cet article n&amp;#8217;est pas soumis à la licence Creative Commons&amp;#160;: tous les droits de cet article sont réservés.&lt;br /&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Ajax répond à une demande&amp;#160;: c&amp;#8217;est l&amp;#8217;un des outils principaux permettant de concevoir une application riche apportant une nouvelle expérience à l&amp;#8217;utilisateur. Elle est devenue une technologie très à la mode, mais qui reste malheureusement assez mal utilisée. Nous donc allons voir dans quels cas elle est utile, et quelques règles fondamentales de la conception d&amp;#8217;application avec Ajax.&lt;/p&gt;
&lt;p&gt;Cet article explique&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;en quoi consiste une application web et la place d&amp;#8217;Ajax dans son architecture&lt;/li&gt;
&lt;li&gt;comment concevoir des interfaces riches avec Ajax et le DOM&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ce qu&amp;#8217;il faut savoir&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;maîtriser la conception d&amp;#8217;applications avec PHP&lt;/li&gt;
&lt;li&gt;avoir des bonnes bases de XML, XHTML et Javascript&lt;/li&gt;
&lt;/ul&gt;    &lt;h3&gt;Ajax permet de concevoir des applications Web&lt;/h3&gt;
&lt;p&gt;C&amp;#8217;est assurément à la mode&amp;#160;: tout le monde en parle comme la technologie qui révolutionne le web. Concrètement, Ajax permet de mettre à jour le contenu de la page sans la recharger complètement. De ce simple fait, on peut aujourd&amp;#8217;hui concevoir des sites qui deviennent  particulièrement puissants, proposant de nombreuses fonctions à l&amp;#8217;utilisateur directement dans son navigateur. La navigation sur le site s&amp;#8217;approche plutôt de la manipulation d&amp;#8217;un logiciel, le look en plus. On aime alors parler de RIA, pour &lt;em&gt;Rich Internet Application&lt;/em&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Une RIA est typiquement composée d&amp;#8217;une interface cliente gérée par le navigateur, conçue avec Ajax, et d&amp;#8217;un support arrière gérant les données sur le serveur, programmée dans un langage de scripts Web plus traditionnel comme PHP.&lt;/p&gt;
&lt;p&gt;Ainsi, l&amp;#8217;essentiel de l&amp;#8217;application étant sur internet, elle devient totalement portable. D&amp;#8217;une part, l&amp;#8217;utilisateur n&amp;#8217;a plus rien à installer, et peut retrouver son environnement de travail, automatiquement mis à jour, sur chaque poste accueillant un navigateur récent sans même avoir à se
soucier du système d&amp;#8217;exploitation qu&amp;#8217;il utilise. D&amp;#8217;autre part, l&amp;#8217;application bénéficie d&amp;#8217;un contenu renouvelé en permanence, grâce aux  administrateurs ou à une communauté d&amp;#8217;utilisateurs dont les contributions sont centralisées dans une seule base de données.&lt;/p&gt;
&lt;p&gt;&lt;img title=&quot;Organisation typique d'une application internet riche&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;Organisation typique d'une application internet riche&quot; src=&quot;http://www.martiusweb.net/public/phpsolutions/phpsolajax.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Au final, Ajax permet de lier les avantages d&amp;#8217;internet aux logiciels classiques, et apporte à l&amp;#8217;utilisateur un confort que l&amp;#8217;on trouvait sur internet grâce à Flash ou Java, qui étaient moins accessibles.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;un point de vue technique, Ajax est basé sur Javascript, un langage interprété par le navigateur qui permet de modifier son comportement en fonction des actions de l&amp;#8217;utilisateur. Des événements sont surveillés par le navigateur qui déclenche alors une série d&amp;#8217;actions. Dans le cas d&amp;#8217;Ajax, on envoie une requête au serveur, qui retourne du contenu au format XML, c&amp;#8217;est ainsi que l&amp;#8217;ont peut faire varier le contenu d&amp;#8217;une manière sensiblement plus agréable pour l&amp;#8217;utilisateur.&lt;/p&gt;
&lt;h3&gt;Ajax n&amp;#8217;est pas un gadget&lt;/h3&gt;
&lt;p&gt;Il est impératif d&amp;#8217;avoir en tête que les avantages d&amp;#8217;Ajax sont directement liés à ses inconvénients. Premièrement, la communication entre le client et le serveur s&amp;#8217;effectue toujours avec le protocole HTTP, donc de manière ponctuelle. L&amp;#8217;organisation de l&amp;#8217;application est très dépendante de cette limite&amp;#160;: il faut en particulier prévoir comment gérer les données et les objets persistants entre chaque échange client-serveur. Ce problème de conception, comme d&amp;#8217;autres, existe bien sûr depuis qu&amp;#8217;il existe des applications dynamiques sur internet, mais Ajax apporte un niveau de complexité supplémentaire non négligeable, notamment en terme de sécurité.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;autre part, Ajax est une jeune technologie, donc au nombreux pré-requis techniques. Il est nécessaire que le visiteur possède un navigateur récent, configuré de manière à ce que le Javascript et les cookies soient activés. Les navigateurs alternatifs, comme les navigateurs mobiles ou les lecteurs d&amp;#8217;écrans (navigateurs vocaux ou en braille) sont souvent limités en fonctionnalités et ne supportent généralement pas le Javascript, donc très rarement Ajax. Les appareils mobiles, tout comme les vieux ordinateurs sont généralement peu puissants et ne possèdent pas toujours
suffisamment de mémoire pour supporter des manipulations dynamiques lourdes, les pages risquent donc de ne pas pouvoir s&amp;#8217;afficher.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;utilisateur doit aussi avoir une bonne connexion à internet à disposition&amp;#160;: illimitée, car les pages modifiées par Ajax ne sont pas consultables hors-ligne, et avec un bon débit car les fichiers Javascript sont souvent lourds. Il faut garder en tête que tout le monde ne dispose pas d&amp;#8217;une connexion ADSL dans toute circonstance&amp;#160;: certaines personnes n&amp;#8217;ont accès à internet que depuis leur lieu de travail par exemple, ou d&amp;#8217;autres utilisent des connexions mobiles de type 3G, qui sont facturée à la durée de connexion et au volume des données transférées.&lt;/p&gt;
&lt;p&gt;Ces contraintes limitent le nombre de visiteurs potentiels sur le site, et de fait, brident l&amp;#8217;accès à l&amp;#8217;information que vous souhaitez distribuer. Comme nous l&amp;#8217;avons déjà évoqué, l&amp;#8217;utilisation d&amp;#8217;Ajax doit donc être justifiée, et pourra être un choix judicieux pour une application interne à une entreprise où le parc informatique est maîtrisé ou si vous ciblez un profil d&amp;#8217;utilisateur particulier.&lt;/p&gt;
&lt;p&gt;Ajax n&amp;#8217;a donc pas systématiquement sa place dans l&amp;#8217;architecture d&amp;#8217;un site internet. Par exemple, le site promotionnel d&amp;#8217;une marque ou
d&amp;#8217;une entreprise n&amp;#8217;a généralement besoin que d&amp;#8217;une série de pages HTML élégantes et bien conçues. Le site internet d&amp;#8217;un journal, même si il est conçue sur une base dynamique côté serveur (pour la mise à jour des articles en temps réel par exemple) doit être composé de pages claires et accessibles, et doit donc limiter les fonctionnalités secondaires, à moins de proposer une alternative minimaliste qui permet quand même l&amp;#8217;accès à l&amp;#8217;information.&lt;/p&gt;
&lt;p&gt;Il ne faut tout de même pas se méprendre&amp;#160;: Ajax est loin d&amp;#8217;être parfait. L&amp;#8217;un des défauts majeurs trop souvent oublié, c&amp;#8217;est que le
développeur doit, d&amp;#8217;une certaine manière, réinventer la roue en programmant manuellement l&amp;#8217;ensemble des opérations de transaction par HTTP&amp;#160;: requête, traitement des erreurs, réception et traitement du flux de données entrantes, alors que ce est travail normalement effectué en totalité par le navigateur.&lt;/p&gt;
&lt;p&gt;Ce n&amp;#8217;est pas non plus une technologie normalisée, les navigateurs ne l&amp;#8217;implémentent pas tous de la même manière et le développeur perd beaucoup de temps à rendre son code compatible avec la majorité des configurations. Il est possible de palier à ce problème et de lisser l&amp;#8217;implémentation d&amp;#8217;Ajax grâce à l&amp;#8217;un des nombreux frameworks disponibles, sur lesquels nous reviendront. Mais ceux-ci sont généralement très lourd, que ce soit par rapport au poids du fichier ou la mémoire utilisée par le navigateur lors de l&amp;#8217;interprétation de ce framework.&lt;/p&gt;
&lt;p&gt;Avec X/HTML5, actuellement en cours d&amp;#8217;élaboration, on peut espérer que ces principales lacunes disparaissent et que les navigateurs gèrent de mieux en mieux l&amp;#8217;implémentation de technologies et outils pour les applications riches.&lt;/p&gt;
&lt;h3&gt;L&amp;#8217;organisation d&amp;#8217;une application Web&lt;/h3&gt;
&lt;p&gt;Classiquement, l&amp;#8217;utilisateur entre une adresse dans son navigateur, le navigateur se charge d&amp;#8217;émettre la requête HTTP (1.1)
complète au serveur qui renvoie le document (généralement HTML ou XML). Le navigateur, en interprétant la page effectue une série d&amp;#8217;appels pour chaque fichier (feuilles de styles, images, Javascript) attaché au premier document. Lorsque l&amp;#8217;utilisateur émet (formulaire) ou veut obtenir (lien hypertexte) de nouvelles données, le navigateur renvoie une requête, traitée par l&amp;#8217;application sur le serveur et la nouvelle page est transmise. L&amp;#8217;ensemble du traitement de l&amp;#8217;application s&amp;#8217;effectue sur le serveur, et la page retournée et en quelque sorte un reflet des données de l&amp;#8217;application.
L&amp;#8217;interactivité est très faible puisque le serveur prend le relais à chaque action de l&amp;#8217;utilisateur. C&amp;#8217;est ce que les spécialistes aiment aujourd&amp;#8217;hui appeler l&amp;#8217;architecture &amp;#8220;Web 1.0&amp;#8221;. C&amp;#8217;est un peu snob, mais c&amp;#8217;est comme ça&amp;#160;!&lt;/p&gt;
&lt;p&gt;La différence avec les applications Web 2.0, c&amp;#8217;est qu&amp;#8217;il est possible d&amp;#8217;utiliser une autre manière pour discuter avec le serveur&amp;#160;: un objet introduit dans le langage Javascript au centre d&amp;#8217;Ajax&amp;#160;: &lt;code&gt;XMLHttpRequest&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Comme son nom l&amp;#8217;indique, cet objet contient un certain nombre de propriétés et méthodes permettant d&amp;#8217;envoyer et recevoir une requête HTTP manuellement. La page n&amp;#8217;est plus rechargée dans sa totalité car la requête est traitée au cours de l&amp;#8217;exécution des scripts de la page courante. Dans le cas d&amp;#8217;Ajax, le résultat de la requête est un document de données au format XML, qui bénéficie d&amp;#8217;une compatibilité native avec le navigateur et bénéficie d&amp;#8217;une API très pratique pour le manipuler&amp;#160;: le DOM.&lt;/p&gt;
&lt;p&gt;Nous allons donc étudier de plus près les différents aspects de l&amp;#8217;utilisation de l&amp;#8217;objet &lt;code&gt;XMLHTTPRequest&lt;/code&gt;. Le code présenté est sommaire, et comme nous le verrons plus loin, le développeur ne traite pas directement avec l&amp;#8217;objet mais utilise des frameworks apportant quelques facilités.&lt;/p&gt;
&lt;h4&gt;La requête HTTP&lt;/h4&gt;
&lt;p&gt;En utilisant la version 1.1 du protocole HTTP, c&amp;#8217;est à dire la plus répandue aujourd&amp;#8217;hui, une requête se présente sous cette forme&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;http sourcecode http&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;GET /page.php?foo=yes&amp;amp;bar=no HTTP/1.1&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Host: www.domaine.com&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.1.1) Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy)&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Accept: text/html, text/xml&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Accept-Encoding: Gzip, deflate&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Accept-Charset: UTF-8, ISO-8859-1&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Referer: http://martiusweb.net/index.php&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;If-Modified-Since: Wed, 27 Apr 2005 17:11:24 GMT&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;[...]&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Il est intéressant de connaître ce format, même si il est assez rarement utilisé par le développeur. En effet, pour analyser votre application ou la débugguer, vous gagnerez beaucoup de temps en regardant directement le contenu des requêtes. Certains outils de débuggage permettent par ailleurs de l&amp;#8217;exploiter pour détecter d&amp;#8217;éventuels problèmes.&lt;/p&gt;
&lt;p&gt;La première ligne contient toujours trois informations. En premier, la méthode de transfert,  généralement GET ou POST, avec lesquels vous devriez être familier. Il existe d&amp;#8217;autres méthodes (telles que PUT), mais elle ne sont pas (ou peu) supportées par les navigateurs, et donc inexistantes avec Ajax. En deuxième, on trouve l&amp;#8217;adresse du document à consulter sur le serveur avec ses éventuels paramètres.
Enfin on précise le protocole utilisé et sa version.&lt;/p&gt;
&lt;p&gt;Les lignes suivantes concernent les en-têtes. Nous allons présenter les principales, que l&amp;#8217;on retrouve presque systématiquement.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;Host&lt;/code&gt; correspond au domaine hôte du document. Parfois il est absent des éléments d&amp;#8217;en-tête car directement intégré dans l&amp;#8217;adresse de la requête.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;User-Agent&lt;/code&gt; permet au client de se présenter. Il indique le système d&amp;#8217;exploitation utilisé avec plus ou moins de précision sur l&amp;#8217;architecture du système et le navigateur utilisé.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Accept&lt;/code&gt; précise les formats de données acceptés. Cet élément est particulièrement important actuellement, car il est un indicateur des différences de compatibilité entre les navigateurs.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Accept-Language&lt;/code&gt; indique ensuite les langues préférées par l&amp;#8217;utilisateur (selon sa configuration), dans l&amp;#8217;ordre de priorité. Cet élément d&amp;#8217;en-tête très utile est généralement oublié par les développeurs de sites en plusieurs langues, qui redirigent systématiquement le visiteur vers une page lui demandant de choisir sa localisation, alors que l&amp;#8217;information est déjà disponible. Pour le confort de l&amp;#8217;utilisateur, on peut commencer par tester l&amp;#8217;en-tête, lui proposer de modifier ce choix en le stockant dans un cookie ou enfin, utiliser la langue par défaut du site si les autres tentatives de définition s&amp;#8217;avèrent infructueuses.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Accept-Encoding&lt;/code&gt; définit si le navigateur supporte une méthode de compression des données. Généralement, le serveur web se charge lui-même de compresser les pages si le client l&amp;#8217;accepte.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Accept-Charset&lt;/code&gt; indique le type d&amp;#8217;encodage des caractères supportés par défaut. Il est peu utilisé, car généralement un site internet n&amp;#8217;en propose qu&amp;#8217;un seul. L&amp;#8217;internationalisation des applications incite généralement les développeurs à utiliser le système unicode (UTF-8), qui couvre la majorité des alphabets. Cependant, un caractère est alors codé sur plusieurs octet, un paragraphe de données sera donc plus volumineux.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Referer&lt;/code&gt; indique la page sur laquelle l&amp;#8217;utilisateur se situe au moment de la requête, autrement dit, la page qui a conduit l&amp;#8217;utilisateur à votre page. Cet élément n&amp;#8217;est pas toujours présent, ou parfois vide, mais il est particulièrement utile pour emmètre des statistiques
d&amp;#8217;audience ou contrôler l&amp;#8217;origine de l&amp;#8217;utilisateur pour des raisons de sécurité.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;If-Modified-Since&lt;/code&gt; indique au serveur qu&amp;#8217;il est utile de renvoyer le contenu du document à la condition qu&amp;#8217;il ai été modifié depuis la date indiquée. Pensez à utiliser cet élément autant que possible, car il peut être très pratique pour préserver la bande passante de transferts
inutiles, sans pour autant implémenter des techniques lourdes pour tester.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;De nombreux autres éléments peuvent être ajoutés à l&amp;#8217;en-tête, je vous invite à consulter les documentations à ce sujet sur internet.&lt;/p&gt;
&lt;p&gt;La réponse est composée des en-têtes et du contenu du document lui même. La séparation est marquée par une ligne vide entre les deux
parties. Voici un exemple de réponse&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;http sourcecode http&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;HTTP/1.1 200 OK&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Date: Mon, 25 Feb 2007 14:16:00 GMT&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Server: Apache/2.0.0 With mod-php5, mod-python&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;X-Powered-By: PHP/5.1.2&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Content-Type: text/html; charset=UTF-8&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Cache-Control: max-age=60&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;[...]&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Contenu du document&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;La réponse est composée des en-têtes et du contenu du document lui même. La séparation est marquée par une ligne vide entre les deux
parties.&lt;/p&gt;
&lt;p&gt;La première ligne de l&amp;#8217;en-tête contient les informations sur le protocole, et le code de réponse. Ici &lt;code&gt;200&lt;/code&gt; signifie que la
requête à parfaitement abouti. D&amp;#8217;autres codes d&amp;#8217;erreur courants sont par exemple &lt;code&gt;403&lt;/code&gt;, qui signifie que l&amp;#8217;utilisateur n&amp;#8217;est pas
autorisé à consulter le document, &lt;code&gt;404&lt;/code&gt;, qui signifie que le document recherché n&amp;#8217;existe pas ou &lt;code&gt;500&lt;/code&gt; dans le cas d&amp;#8217;une erreur interne du serveur, qui cache généralement un problème de configuration du serveur web.&lt;/p&gt;
&lt;p&gt;Les lignes suivantes sont d&amp;#8217;autres éléments d&amp;#8217;en-tête. Les information de date et de durée de validité , tels que &lt;code&gt;Date&lt;/code&gt; ou
&lt;code&gt;Cache-Control&lt;/code&gt; sont particulièrement utiles, encore une fois, pour minimiser le trafic superflu.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;autres informations concernant le serveur sont délivrées dans la requête, comme &lt;code&gt;Server&lt;/code&gt; ou &lt;code&gt;X-Powered-By&lt;/code&gt;
On préfixe généralement les éléments dont le sens n&amp;#8217;est pas défini par le protocole HTTP par &lt;code&gt;X-&lt;/code&gt;. Sachez que vous pouvez ajouter, si vous en avez l&amp;#8217;utilité, certains éléments d&amp;#8217;en-tête propres à votre application.&lt;/p&gt;
&lt;p&gt;Sachez également observer l&amp;#8217;environnement d&amp;#8217;exécution de votre application. Dans le cas d&amp;#8217;un serveur web comme Apache, des traces
des échanges sont archivés, notamment dans les fichiers log de l&amp;#8217;application. Certains outils proposent par ailleurs de les analyser pour vous, comme &lt;em&gt;analog&lt;/em&gt; sous Linux.&lt;/p&gt;
&lt;h5&gt;Plus d&amp;#8217;informations sur HTTP et Apache&lt;/h5&gt;
&lt;p&gt;N&amp;#8217;hésitez pas à vous documenter sur les subtilités du protocole HTTP et Apache, ou n&amp;#8217;importe quel autre serveur web que vous
souhaitez utiliser.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://www.w3.org/Protocols/&quot; hreflang=&quot;en&quot;&gt;http://www.w3.org/Protocols/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://httpd.apache.org/docs/2.0/fr/&quot; hreflang=&quot;en&quot;&gt;http://httpd.apache.org/docs/2.0/fr/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.cybersdf.org/2005/07/09/128-le-http-pour-les-nuls&quot; hreflang=&quot;en&quot;&gt;http://www.cybersdf.org/2005/07/09/128-le-http-pour-les-nuls&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Le flux de données XML&lt;/h4&gt;
&lt;p&gt;Les données XML sont la réponse à la requête émise par Ajax. Le flux sera donc réceptionné par l&amp;#8217;objet &lt;code&gt;XMLHttpRequest&lt;/code&gt; avant que l&amp;#8217;on puisse l&amp;#8217;utiliser. La construction de votre document XML aura une très forte influence sur le reste de votre interface client, une étape de réflexion sur la façon dont vous souhaitez manipuler ces données est donc incontournable.&lt;/p&gt;
&lt;p&gt;Dans un premier temps, identifiez clairement les données à transmettre. Regroupez-les en fonction de leur sens et de leurs liens. Un premier tri sera généralement la séparation entre les données métier de votre application et les éventuelles informations correspondant à la manière dont doit évoluer l&amp;#8217;interface avec ces informations.&lt;/p&gt;
&lt;p&gt;Il faut ensuite modéliser vos données en XML. En suivant la méthode rigoureusement, ça ne devrait pas poser trop de problèmes. Il faut garder en tête que le code lui même doit jouer le rôle de sa propre documentation, il est donc impératif de suivre la logique imposée par XML. A partir de ce moment, le plus gros du travail est fait. Les propriétés d&amp;#8217;un élément se présentent logiquement sous forme d&amp;#8217;attribut, et son contenu (si il existe) et placé entre la balise ouvrante et la balise fermante. Un attribut ne doit jamais être précisé dans un élément fils, à même titre que le contenu n&amp;#8217;a pas sa place dans un attribut. Le code suivant illustre cette problématique avec un exemple un peu grossier.&lt;/p&gt;
&lt;pre class=&quot;xml sourcecode xml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;magazine&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;articles&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;article&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;page&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;01&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;auteur&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Martin Richard&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;auteurid&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;01&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;titre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Concevoir une application pour le web avec Ajax&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/titre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;    &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/article&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/articles&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/magazine&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Voici le même document XML, mieux formé&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;xml sourcecode xml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;magazine&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;article&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;page&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;01&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;titre&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Concevoir une application pour le web avec Ajax&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;auteur&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;auteurid&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;01&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;nom&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Martin Richard&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/article&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;article&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;page&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;02&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;titre&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Le modèle MVC&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;auteur&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;auteurid&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;02&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;nom&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Pierre Durand&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Pierre Durand est ...&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/auteur&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/chapitre&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/article&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/magazine&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;La première grosse erreur est située dès la deuxième ligne, car l&amp;#8217;élément &lt;code&gt;&amp;lt;articles&amp;gt;&lt;/code&gt; n&amp;#8217;est pas utile. On peut penser que
regrouper les différentes éléments identiques dans une même balise, pour les retrouver plus facilement par exemple, est une bonne idée, mais en manipulant le document plus tard, ce choix risque de surprendre, et coûtera une opération en plus pour accéder un niveau plus bas dans la hiérarchie. Une autre manière aurait été de regrouper les articles dans un élément &lt;code&gt;&amp;lt;dossier&amp;gt;&lt;/code&gt; si le magazine est organisé de cette manière.&lt;/p&gt;
&lt;p&gt;La deuxième erreur concerne la ligne suivante, et les deux attributs &lt;code&gt;auteur&lt;/code&gt; et &lt;code&gt;auteurid&lt;/code&gt; L&amp;#8217;auteur n&amp;#8217;est pas un attribut de l&amp;#8217;article, mais un élément à part entière, il est donc plus logique de le considérer comme un élément fils de l&amp;#8217;article, contenant deux attributs. Ici, il est même possible d&amp;#8217;utiliser la balise &lt;code&gt;&amp;lt;auteur&amp;gt;&lt;/code&gt; comme conteneur d&amp;#8217;une description, par exemple. On peut envisager une autre manière d&amp;#8217;exploiter la même syntaxe&amp;#160;: si le document devait être un tri des articles par auteur, notre élément &lt;code&gt;&amp;lt;auteur&amp;gt;&lt;/code&gt; aurait été parent de &lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Enfin, considérer le titre de l&amp;#8217;article comme étant un élément n&amp;#8217;est pas vraiment une erreur, mais puisqu&amp;#8217;il ne contient pas le moindre attribut, il sera beaucoup plus simple d&amp;#8217;y accéder si l&amp;#8217;information est elle-même un attribut de l&amp;#8217;élément article.&lt;/p&gt;
&lt;p&gt;Si votre application à pour but d&amp;#8217;être portable, ou que le format de votre document XML doit être échangeable, il devient nécessaire de fixer la grammaire de ce format, pour que tout le monde se comprenne. Pour fixer un format de document XML, il est possible d&amp;#8217;utiliser un langage conçu pour par le W3C&amp;#160;: le langage de DTD (pour &lt;em lang=&quot;en&quot;&gt;DocType Definition&lt;/em&gt;). Cependant, la syntaxe est assez rigide et la prise en main n&amp;#8217;est pas évidente. Une alternative normalisée assez courante, et supportée par PHP s&amp;#8217;appelle RelaxNG. Ce langage est lui-même issu de XML, et
sa syntaxe est plus accessible. Je vous invite à vous renseigner sur ces deux langages pour vous faire une idée de leur utilisation.&lt;/p&gt;
&lt;h4&gt;Gérer la transaction avec Javascript&lt;/h4&gt;
&lt;p&gt;Il y a plusieurs manière de traiter la requête HTTP, car les frameworks Ajax disponibles implémentent tous leur propre méthode et leurs propres règles. Nous allons ici nous contenter de voir le traitement d&amp;#8217;une requête Ajax avec le code le plus simple possible&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;javascript sourcecode javascript&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* On effectue un test qui permet d'utiliser l'objet&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;* XMLHttpRequest (que l'on appellera XHR) en fonction&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;* du navigateur.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;window.&lt;span style=&quot;color: #006600;&quot;&gt;XMLHttpRequest&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   Ajax = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; XMLHttpRequest&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;window.&lt;span style=&quot;color: #006600;&quot;&gt;ActiveXObject&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;try&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      Ajax = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; ActiveXObject&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'Msxml2.XMLHTTP'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;catch&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;e&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Retour de l'exception, avec Internet Explorer&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* On définie quelques règles de traitement de la requête&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;onreadystatechange&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;readyState&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      traiterResultat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;readyState&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      masquerMessageAjax&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      afficherMessageAjax&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* En toute logique, nos fonctions traiterResultat(),&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;   * afficherMessageAjax() et masquerMessageAjax() seraient&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;   * plutôt les méthodes d'un objet.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;   */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; traiterResultat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;status&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// La requête est parfaitement passée,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// on peut l'utiliser.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;status&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;403&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;||&lt;/span&gt; Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;status&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;404&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;||&lt;/span&gt; Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;status&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// on affiche un message d'erreur&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;open&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'GET'&lt;/span&gt;,&lt;span style=&quot;color: #3366CC;&quot;&gt;'page.php?param='&lt;/span&gt;+valParam, &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;En premier, il faut créer un objet &lt;code&gt;XMLHttpRequest&lt;/code&gt; (que l&amp;#8217;on appellera XHR), en vérifiant le navigateur utilisé, car Microsoft le considère comme un objet &lt;em&gt;ActiveX&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Avant de lancer la requête, nous allons définir la politique qui permet de suivre son évolution. L&amp;#8217;objet XHR met à disposition la propriété
&lt;code&gt;XHR.readyState&lt;/code&gt; qui prend pour valeur un code numérique correspondant à un état de la requête.  Les codes sont &lt;code&gt;0&lt;/code&gt; quand la requête n&amp;#8217;a pas été initialisée, &lt;code&gt;1&lt;/code&gt; quand elle est en train de charger, &lt;code&gt;2&lt;/code&gt; quand elle a été reçue, &lt;code&gt;3&lt;/code&gt; pendant que le navigateur est en train de la traiter et &lt;code&gt;4&lt;/code&gt; quand elle est terminée, et donc que nous allons pouvoir utiliser son résultat.&lt;/p&gt;
&lt;p&gt;Pour surveiller les changements d&amp;#8217;état, il existe un événement &lt;code&gt;XHR.onreadystatechange&lt;/code&gt; auquel on attache une fonction qui va par exemple afficher un message d&amp;#8217;attente tant que la requête n&amp;#8217;est pas terminée et déclencher le traitement quand le code état sera &lt;code&gt;4&lt;/code&gt;. Le message d&amp;#8217;attente doit être assez clair et amené sans ambiguïté (il ne doit pas être pris pour un message d&amp;#8217;erreur par exemple), évitez par ailleurs d&amp;#8217;utiliser des termes techniques qui risquent d&amp;#8217;embrouiller. Généralement, un message pour les trois états intermédiaires suffisent. De nombreux générateurs d&amp;#8217;images d&amp;#8217;attentes animées sont disponibles sur internet, ces images sont très pratiques car certains motifs sont très répandus, et les utilisateurs y sont déjà habitués.&lt;/p&gt;
&lt;p&gt;La première étape pour traiter le résultat, c&amp;#8217;est de vérifier les éventuelles erreurs. La première vérification est le code de réponse de la requête HTTP, représentée par l&amp;#8217;attribut &lt;code&gt;Ajax.status&lt;/code&gt;. Le code de réussite, nous l&amp;#8217;avons vu plus haut est le code &lt;code&gt;200&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Il peut être dans votre intérêt d&amp;#8217;utiliser les codes d&amp;#8217;erreur HTTP si ils peuvent correspondre à l&amp;#8217;erreur constatée. Par exemple, renvoyez le code &lt;code&gt;403&lt;/code&gt; si l&amp;#8217;utilisateur à fait appel à une fonction qu&amp;#8217;il n&amp;#8217;avait pas le droit d&amp;#8217;utiliser, vous pouvez par ailleurs transmettre un message personnalisé (en XML ou en texte brut) même si vous renvoyez un code d&amp;#8217;erreur. Pensez bien sûr à définir une syntaxe pour vos messages d&amp;#8217;erreur, même si elle est simpliste.&lt;/p&gt;
&lt;p&gt;Une fois que tout est prêt, la requête peut-être crée et envoyée avec les fonction &lt;code&gt;open()&lt;/code&gt; et &lt;code&gt;send()&lt;/code&gt;. L&amp;#8217;exemple présenté utilise la méthode GET pour l&amp;#8217;envoi, c&amp;#8217;est pourquoi le paramètre passé à la fonction &lt;code&gt;send()&lt;/code&gt; est &lt;code&gt;null&lt;/code&gt;
Enfin, le dernier paramètre de la fonction &lt;code&gt;open()&lt;/code&gt; permet de choisir si l&amp;#8217;envoi sera synchrone. Ici fixé à la valeur &lt;code&gt;false&lt;/code&gt;, il est donc asynchrone. Cela signifie que le script n&amp;#8217;attend pas le résultat de la requête pour continuer son exécution.&lt;/p&gt;
&lt;h3&gt;Pratiques de conception&lt;/h3&gt;
&lt;p&gt;Il existe des pratiques et des méthodes qui ont été étudiées par certaines entreprises et certains développeurs spécialisés. Généralement, il s&amp;#8217;agit d&amp;#8217;adapter les méthodes déjà existantes au nouvel outil Ajax. Cependant, ces pratiques sont essentielles pour concevoir une application viable. En voici quelques unes.&lt;/p&gt;
&lt;h3&gt;Pratiques de conception&lt;/h3&gt;
&lt;p&gt;Il existe des pratiques et des méthodes qui ont été étudiées par certaines entreprises et certains développeurs spécialisés. Généralement, il s&amp;#8217;agit d&amp;#8217;adapter les méthodes déjà existantes au nouvel outil Ajax. Cependant, ces pratiques sont essentielles pour concevoir une application viable. En voici quelques unes.&lt;/p&gt;
&lt;h4&gt;Choisissez vos outils&lt;/h4&gt;
&lt;p&gt;Pour bien travailler, il faut un bon environnement de travail, et donc des bons outils. Dans le cas des applications pour le web, efficace n&amp;#8217;est pas toujours lié à coûteux, et de nombreux logiciels gratuits ou libres sont à disposition des développeurs.&lt;/p&gt;
&lt;p&gt;Le choix de l&amp;#8217;éditeur est essentiel. Si vous avez l&amp;#8217;habitude d&amp;#8217;utiliser l&amp;#8217;éditeur Eclipse pour concevoir vos applications, je vous invite à vous pencher sur Aptana, ce logiciel est également disponible sous forme de  plug-in pour votre Eclipse. Aptana intègre de nombreux outils pour les développeurs web et le support de nombreux frameworks. Préférez un éditeur avec lequel vous vous sentez à l&amp;#8217;aise et qui soit à la taille de votre projet. Il est inutile de choisir un éditeur trop lourd pour un projet de petite taille, alors qu&amp;#8217;un éditeur avec des outils de débbugage avancés et capable d&amp;#8217;interagir avec votre serveur web sera particulièrement pratique lorsque votre projet prendra du volume. Quoi qu&amp;#8217;il en soit, évitez
de changer de logiciel en cours de route, au risque de perdre beaucoup de temps pour vous réadapter.&lt;/p&gt;
&lt;p&gt;Le navigateur firefox sera également un outil précieux pendant le processus de développement, notamment grâce à ses nombreuses extensions. La barre d&amp;#8217;outil du développeur web vous facilitera en particulier la conception des feuilles de style CSS, et Firebug vous offrira un
outil très complet pour faire des tests de vitesse ou manipuler le DOM. L&amp;#8217;inspecteur DOM, fourni par les développeurs de Firefox, permet de naviguer dans l&amp;#8217;arbre tel que le navigateur l&amp;#8217;a interprété. Ces trois extensions sont presque incontournables, mais il en existe bien d&amp;#8217;autres.&lt;/p&gt;
&lt;p&gt;Enfin, pour programmer dans de bonnes conditions, il est nécessaire d&amp;#8217;avoir à portée de main les principales documentations des langages que vous utilisez. Vous avez déjà la documentation PHP (&lt;a href=&quot;http://fr.php.net/&quot;&gt;http://fr.php.net/&lt;/a&gt;) à portée de main, mais d&amp;#8217;autres ressources vous seront utiles, comme sur &lt;a href=&quot;http://web.developpez.com&quot;&gt;http://web.developpez.com&lt;/a&gt;. Un très bon site
regroupe également la liste des balises XHTML 1.1 et les attributs disponibles (&lt;a href=&quot;http://giminik.developpez.com/xhtml/&quot;&gt;http://giminik.developpez.com/xhtml/&lt;/a&gt;). Les documents du W3C (&lt;a href=&quot;http://www.w3.org&quot;&gt;www.w3.org&lt;/a&gt;) vous seront, quand à eux,
utiles pour vérifier des points précis d&amp;#8217;une norme.&lt;/p&gt;
&lt;h4&gt;HTML, XML et l&amp;#8217;API Dom&lt;/h4&gt;
&lt;p&gt;Pour faire évoluer votre page sans la recharger, il est indispensable d&amp;#8217;utiliser une API proposée par le W3C appelée DOM (pour &lt;em lang=&quot;en&quot;&gt;Document Object Model&lt;/em&gt; pour modèle objet du document). Grâce à DOM, vous avez à disposition d&amp;#8217;un bon nombre d&amp;#8217;objets et de méthodes vous permettant de modifier le corps d&amp;#8217;un document XML. XHTML reposant sur XML, se conformer à cette norme devient également incontournable.&lt;/p&gt;
&lt;p&gt;Le DOM organise le document XML en noeuds (&lt;em&gt;node&lt;/em&gt;). Un noeud contient un certain nombre d&amp;#8217;éléments, les attributs éventuels, un contenu de type texte ou une série d&amp;#8217;autres noeuds. Observez bien la manière dont l&amp;#8217;arbre est construit par Firefox depuis l&amp;#8217;extension Inspecteur DOM, vous remarquerez au passage que les retours à la ligne et les tabulations utilisées pour mettre en forme le code sont considérées comme des éléments texte d&amp;#8217;un noeud.&lt;/p&gt;
&lt;p&gt;DOM est décliné dans de nombreux langages, dont Javascript et PHP5.&lt;/p&gt;
&lt;p&gt;En Javascript, il se manipule à partir de l&amp;#8217;objet racine &lt;code&gt;document&lt;/code&gt;. On accède aux noeuds fils du noeud courant avec &lt;code&gt;monNoeud.childNodes&lt;/code&gt;, par exemple pour accéder à l&amp;#8217;élément HTML, il suffit d&amp;#8217;utiliser &lt;code&gt;document.childNodes[1]&lt;/code&gt;, ou encore &lt;code&gt;document.firstNode&lt;/code&gt;. D&amp;#8217;autres attributs sont disponibles, à savoir &lt;code&gt;monNoeud.lastNode&lt;/code&gt;, &lt;code&gt;monNoeud.nextSibling&lt;/code&gt; ou &lt;code&gt;monNoeud.previousSibling&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Des méthodes de recherche sont également disponibles, comme &lt;code&gt;monNoeud.getElementsByTagName('div')&lt;/code&gt;,
qui retourne un tableau contenant chaque noeud de type &lt;code&gt;div&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;autres méthodes permettent de créer ou modifier certains noeuds, comme &lt;code&gt;createElement()&lt;/code&gt; ou &lt;code&gt;createTextNode()&lt;/code&gt;. Vous pouvez ensuite les insérer dans le DOM avec &lt;code&gt;appendChild()&lt;/code&gt;, &lt;code&gt;insertBefore()&lt;/code&gt;, &lt;code&gt;replaceChild()&lt;/code&gt; ou même en supprimer un avec &lt;code&gt;removeChild()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Entraînez vous à naviguer dans le DOM, avec de l&amp;#8217;habitude, l&amp;#8217;accès à n&amp;#8217;importe quel élément de la page sera un jeu d&amp;#8217;enfant. L&amp;#8217;exemple de code suivant donne un aperçu de la manipulation du DOM en Javascript&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;javascript sourcecode javascript&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* Pour manipuler le DOM, la page doit être chargée, donc&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;* on attend l'évènement onload.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;window.&lt;span style=&quot;color: #000066;&quot;&gt;onload&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// On garde en mémoire le premier paragraphe de la page &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   paragraphe = document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;p&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// On construit un nouvel élément titre contenant du texte &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   precision = document.&lt;span style=&quot;color: #006600;&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;appendChild&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;document.&lt;span style=&quot;color: #006600;&quot;&gt;createTextNode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&amp;quot;Titre de page&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// On injecte cet élément juste avant le premier paragraphe &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   paragraphe.&lt;span style=&quot;color: #006600;&quot;&gt;parentNode&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;insertBefore&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;precision, paragraphe&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;DOM sera énormément utilisé avec Javascript. Il servira à manipuler les documents XML obtenus par les requêtes Ajax ou implémenter les éléments de l&amp;#8217;interface qui la rendent dynamique (boutons supplémentaires, messages de retour, &amp;#8230;).
DOM sera certainement utile en PHP également. L&amp;#8217;implémentation est très semblable à celle de Javascript, certaines méthodes supplémentaires ont été ajoutées, notamment en ce qui concerne la manipulation des fichiers ou la vérification de la conformité d&amp;#8217;un document d&amp;#8217;après sa DTD. Le listing suivant présente un aperçu de l&amp;#8217;implémentation de DOM avec PHP5. L&amp;#8217;implémentation varie en PHP4, car les noms de fonctions ont été adaptés à la nomenclature classique de PHP.&lt;/p&gt;
&lt;pre class=&quot;php sourcecode php&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$xml&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; DOMDocument&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// D'après le listing n° 4&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$xml&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'listing4.xml'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Obtenir les articles &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$articles&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$xml&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;documentElement&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'article'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// Titre du premier article &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;$titre&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #ff0000&quot;&gt;$articles&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #006600;&quot;&gt;getAttribute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'titre'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;En PHP on charge un fichier avec la fonction &lt;code&gt;load()&lt;/code&gt;. Il est possible de charger un flux dans une variables avec la fonction &lt;code&gt;loadXML()&lt;/code&gt;. Pour charger du HTML, il existe deux fonctions spécifiques&amp;#160;: &lt;code&gt;loadHTML()&lt;/code&gt; ou &lt;code&gt;loadHTMLFile()&lt;/code&gt;. Pour enregistrer le résultat &lt;code&gt;save()&lt;/code&gt; et &lt;code&gt;saveHTMLFile()&lt;/code&gt; s&amp;#8217;en chargeront, et pour récupérer le résultat dans une variable, il faudra utiliser &lt;code&gt;saveXML()&lt;/code&gt; et &lt;code&gt;saveHTML()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Pour valider un flux XML d&amp;#8217;après la DTD, utilisez la fonction &lt;code&gt;validate()&lt;/code&gt;, la DTD étant précisée dans la première ligne du fichier (si elle existe), PHP se charge de l&amp;#8217;obtenir. Si le format du flux a été définit en utilisant RelaxNG, utilisez &lt;code&gt;relaxNGValidate()&lt;/code&gt; ou &lt;code&gt;relaxNGValidateSource()&lt;/code&gt; si le schéma est stocké dans une variable.&lt;/p&gt;
&lt;p&gt;Les fonctions propres à la navigation ou la modification du DOM sont identiques (à quelques exceptions près) entre PHP5 et Javascript.&lt;/p&gt;
&lt;p&gt;La manipulation du DOM avec PHP est moins courante. Pour créer un flux XML, l&amp;#8217;API SimpleXML sera généralement plus pratique, bien que moins puissante. DOM peut être utile pour modifier dynamiquement un fichier XML enregistré physiquement, ou téléchargé depuis un serveur distant.&lt;/p&gt;
&lt;h4&gt;Choisir un framework Javascript&lt;/h4&gt;
&lt;p&gt;Un choix généralement important à notre niveau est le choix
d&amp;#8217;un framework Javascript. Il en existe plusieurs sur internet, qui
ont tous leurs avantages et inconvénients.&lt;/p&gt;
&lt;p&gt;Généralement, ces frameworks sont répartis en plug-ins, il est
donc possible de sélectionner les fonctionnalités dont vous avez
besoin et éliminer celles dont vous n&amp;#8217;avez pas l&amp;#8217;utilité. Par
ailleurs, certains frameworks seront plus portés sur l&amp;#8217;amélioration
des possibilités du dom, certains implémenteront aussi un certain
nombre d&amp;#8217;effets visuels améliorant l&amp;#8217;interface alors que d&amp;#8217;autres se
concentreront sur la communication entre le client et le serveur avec
Ajax ou certaines alternatives.&lt;/p&gt;
&lt;p&gt;Le choix d&amp;#8217;un framework dépend de vos besoins, mais à nouveau,
ce choix doit être réalisé assez tôt dans la conception, car vous
en serez dépendant.&lt;/p&gt;
&lt;p&gt;Voici une petite liste de frameworks courants, c&amp;#8217;est à vous de
choisir en détail celui qui vous semble le plus approprié à vos
besoins. La réactivité de la communauté des utilisateurs et la
qualité de la documentation doit également être un critère jouant
sur votre choix.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;Y!UI (&lt;em&gt;Yahoo! User Interface&lt;/em&gt;)&amp;#160;:
&lt;a href=&quot;http://developer.yahoo.com/yui/&quot;&gt;http://developer.yahoo.com/yui/&lt;/a&gt; Développé et utilisé par les services de Yahoo!, ce framework est fonctionnel et bien documenté. Il reste cependant limité aux besoins internes de la société. C&amp;#8217;est un très bon choix pour se limiter à l&amp;#8217;essentiel (ou presque).&lt;/li&gt;
&lt;li&gt;Mootools&amp;#160;: &lt;a href=&quot;http://www.mootools.net&quot;&gt;http://www.mootools.net&lt;/a&gt; Ce framework est l&amp;#8217;un des plus récents. Son principal avantage est l&amp;#8217;amélioration du DOM grâce à des sélecteurs identiques à ceux utilisés en CSS. Il est également réputé pour être assez léger. Cependant,
certains outils particulièrement appréciés dans d&amp;#8217;autres frameworks sont prévus mais pas encore disponible à ce jour. Il est par ailleurs assez simple d&amp;#8217;utilisation, mais la documentation n&amp;#8217;est pas très pratique.&lt;/li&gt;
&lt;li&gt;Prototype&amp;#160;: &lt;a href=&quot;http://www.prototypejs.org&quot;&gt;http://www.prototypejs.org&lt;/a&gt; Prototype est l&amp;#8217;un des premiers frameworks de ce type apparus. Particulièrement complet et robuste, il intègre des fonctions Ajax et d&amp;#8217;amélioration du DOM puissantes. Un second framework nommé
Scriptaculous (&lt;a href=&quot;http://script.aculo.us&quot;&gt;http://script.aculo.us&lt;/a&gt;) basé sur Prototype dispose de nombreux effets très agréables, mais aussi très lourds.&lt;/li&gt;
&lt;li&gt;jQuery&amp;#160;: &lt;a href=&quot;http://www.jquery.com&quot;&gt;http://www.jquery.com&lt;/a&gt; C&amp;#8217;est un framework très réputés dans les projets open source français, il est notamment utilisé par des applications comme Spip ou DotClear.&lt;/li&gt;
&lt;li&gt;D&amp;#8217;autres frameworks comme Dojo ou Microsoft Atlas peuvent également être cités.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Une dernière alternative est le GWT (&lt;em&gt;Google Web Toolkit&lt;/em&gt;), qui vous permet de programmer la partie cliente de votre application
en Java. Le GWT se chargera de le transcrire en Javascript.&lt;/p&gt;
&lt;h4&gt;Frameworks PHP/Ajax&lt;/h4&gt;
&lt;p&gt;Généralement, le développement de plusieurs applications web
entraîne la programmation de même fonctions plusieurs fois, avec
quelques adaptations propres au projet. Cela devient rapidement
désagréable car très redondant, et risque d&amp;#8217;embrouiller le
développeur qui jongle entre plusieurs standards et règles de
conception variant d&amp;#8217;un projet à l&amp;#8217;autre.&lt;/p&gt;
&lt;p&gt;C&amp;#8217;est pour ces raisons qu&amp;#8217;il existe des frameworks complets vous
imposent des méthodes de conceptions standardisées. Ces frameworks
sont basés sur une architecture stable et des librairies de
fonctions ou classes qui lissent l&amp;#8217;implémentation des outils
classiques comme les bases de données. Leur organisation facilite
également le développement à plusieurs grâce à la séparation de
l&amp;#8217;application en modules indépendants.&lt;/p&gt;
&lt;p&gt;En PHP, quelques frameworks sont jugés réellement matures par la
communauté. Parmis eux, on trouve le projet français Symfony
(&lt;a href=&quot;http://www.symfony-project.org&quot;&gt;http://www.symfony-project.org&lt;/a&gt;). Il repose sur les motifs de
conception MVC et propose de nombreux outils pour faciliter la conception d&amp;#8217;une application ou d&amp;#8217;un site internet, comme la
virtualisation de la base de données, la simplification de l&amp;#8217;internationalisation ou même l&amp;#8217;optimisation du référencement, notamment avec l&amp;#8217;URL Rewriting. Enfin, Symfony simplifie également l&amp;#8217;utilisation d&amp;#8217;Ajax.&lt;/p&gt;
&lt;h4&gt;La répartition client/serveur&lt;/h4&gt;
&lt;p&gt;Ce sujet à déjà été évoqué ponctuellement plus tôt. La
répartition entre le client et le serveur est cruciale pour une
application web, la balance doit être équilibrée pour permettre de
décharger le serveur de certains traitements, mais l&amp;#8217;interface doit
rester fluide, d&amp;#8217;autant plus que décharger la logique métier vers
le client entraîne des risques de sécurité importants.&lt;/p&gt;
&lt;p&gt;En local, on s&amp;#8217;attarde essentiellement sur l&amp;#8217;interface et l&amp;#8217;aspect
utilisateur. On peut par exemple simplifier la saisie et effectuer
une série de tests sur les données entrées par les utilisateurs
avant de les transmettre au serveur. Certains calculs peuvent
également être traiter en local, pour ne renvoyer au serveur que
l&amp;#8217;essentiel, cependant, cet aspect est généralement assez limité.&lt;/p&gt;
&lt;p&gt;La logique métier est systématiquement sur le serveur, le
traitement, la gestion et la redistribution des données se fait
invariablement sur le serveur. Par ailleurs, l&amp;#8217;envoi d&amp;#8217;une requête
avec Ajax doit être effectuée sur le serveur hôte de la page
courante, pour la sécurité de l&amp;#8217;utilisateur.&lt;/p&gt;
&lt;p&gt;Cette répartition, comme tout choix de conception, doit être
délimitée de manière cohérente. Elle entraîne également de
nombreux risques de sécurité. Par exemple, n&amp;#8217;oubliez pas que toute
donnée transmise doit être contrôlée, car il est toujours facile
de détourner le fonctionnement d&amp;#8217;un script et de transmettre des
informations frauduleuses. Chacune des vérifications effectuées en
local doit être reprise sur le serveur. Les failles de sécurité
classiques comme les injections SQL risquent d&amp;#8217;être plus nombreuses,
mais la manière de les éviter est toujours la même&amp;#160;: vérifier la
cohérence des données et échapper les caractères comme les
guillemets utilisés dans les requêtes. Pour finir, les données
sensibles doivent toujours être protégées. Par exemple, si
certaines données doivent être inaccessibles pour un utilisateur
non identifié, les contrôles appliqués lors du chargement d&amp;#8217;une
page doivent également être effectués avant de transmettre une
réponse à une requête Ajax.&lt;/p&gt;
&lt;h4&gt;Organisation de l&amp;#8217;application&lt;/h4&gt;
&lt;p&gt;A l&amp;#8217;image de la partie serveur,  la partie cliente de votre
application doit également être modélisée et organisée. Il est
impératif de veiller à séparer la couche de traitement des données
et de communication avec le serveur de la couche graphique, comme la
modification du DOM de la page ou les effets visuels.&lt;/p&gt;
&lt;p&gt;Le motif de conception MVC peut également être adapté à une
architecture cliente conçue avec Ajax. Le contrôleur sera chargé
d&amp;#8217;analyser les évènements et de déclencher les actions en
conséquence, la vue concerne bien sûr l&amp;#8217;aspect visuel (la couche
&amp;#8220;graphique&amp;#8221;) et le modèle est chargé de communiquer
avec le serveur et de recevoir les données. Le listing qui suit présente
un exemple simplifié d&amp;#8217;architecture MVC appliquée à Ajax.&lt;/p&gt;
&lt;pre class=&quot;javascript sourcecode javascript&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* Nous travaillons avec un formulaire contenant un seul champ&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;* dont l'information est envoyée au serveur avec XMLHttpRequest&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myController = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   start: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Définir les évènements par défaut&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'form'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;onsubmit&lt;/span&gt; = myController.&lt;span style=&quot;color: #006600;&quot;&gt;submitForm&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   submitForm: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      input = document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;input.&lt;span style=&quot;color: #006600;&quot;&gt;value&lt;/span&gt; == &lt;span style=&quot;color: #3366CC;&quot;&gt;''&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         myView.&lt;span style=&quot;color: #006600;&quot;&gt;displayError&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         myView.&lt;span style=&quot;color: #006600;&quot;&gt;disableForm&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         myModel.&lt;span style=&quot;color: #006600;&quot;&gt;sendInformation&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   endOfQuery: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      myView.&lt;span style=&quot;color: #006600;&quot;&gt;stopLoader&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      myView.&lt;span style=&quot;color: #006600;&quot;&gt;enableForm&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;myModel.&lt;span style=&quot;color: #006600;&quot;&gt;result&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;!&lt;/span&gt;= undefined&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         myView.&lt;span style=&quot;color: #006600;&quot;&gt;showResult&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myView = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   dislpayError: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      element = document.&lt;span style=&quot;color: #006600;&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'p'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;appendChild&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;document.&lt;span style=&quot;color: #006600;&quot;&gt;createTextNode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'Champ incomplet'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      input = document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      input.&lt;span style=&quot;color: #006600;&quot;&gt;parentNode&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;insertBefore&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;element, input&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   disableForm: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;disabled&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;disabled&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   enableForm: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;disabled&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;disabled&lt;/span&gt; = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   queryLoader: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// afficher un message d'attente&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   stopLoader: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// masquer le message d'attente&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   showResult: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Traitement du resultat et affichage&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; myModel = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   result: undefined,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   sendInformation: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      Ajax = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; XMLHttpRequest&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;open&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'GET'&lt;/span&gt;, &lt;span style=&quot;color: #3366CC;&quot;&gt;'page.php?text='&lt;/span&gt; + document.&lt;span style=&quot;color: #006600;&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;'input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #CC0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   queryState: &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;readyState&lt;/span&gt; = &lt;span style=&quot;color: #CC0000;&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Ajax.&lt;span style=&quot;color: #000066;&quot;&gt;status&lt;/span&gt; == &lt;span style=&quot;color: #CC0000;&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;            myController.&lt;span style=&quot;color: #006600;&quot;&gt;endOfQuery&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;            &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;result&lt;/span&gt; = Ajax.&lt;span style=&quot;color: #006600;&quot;&gt;responseXML&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;documentElement&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;            myController.&lt;span style=&quot;color: #006600;&quot;&gt;endOfQuery&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;            myController.&lt;span style=&quot;color: #006600;&quot;&gt;queryError&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;      &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;         myView.&lt;span style=&quot;color: #006600;&quot;&gt;queryLoader&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;window.&lt;span style=&quot;color: #000066;&quot;&gt;onload&lt;/span&gt; = myController.&lt;span style=&quot;color: #006600;&quot;&gt;start&lt;/span&gt;;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;L&amp;#8217;organisation de vos fichiers prend également beaucoup d&amp;#8217;importance car une organisation souple permet de tirer partie des avantages du cache du navigateur. Généralement, choisir un fichier par classe est une bonne solution.&lt;/p&gt;
&lt;h4&gt;Optimisations&lt;/h4&gt;
&lt;p&gt;Comme pour toute application, l&amp;#8217;optimisation est ici un point important à ne pas négliger. Une application optimisée signifie un meilleur confort pour l&amp;#8217;utilisateur et surtout une économie de ressources sur le(s) serveur(s).&lt;/p&gt;
&lt;p&gt;Les appels au serveur sont particulièrement coûteux, dans la mesure du possible, c&amp;#8217;est toujours avantageux de les économiser et de les regrouper si possible. Les échanges sur le réseau peuvent aussi être optimisés en réduisant le volume des données échangées. Privilégier des index numériques aux chaînes de caractères dès que possible est déjà un bon point. Dans des cas plus extrêmes, il est parfois intéressant de définir un second format pour les flux XML en réduisant au maximum le nom des attributs et en réduisant les espaces blancs dans le codes. Il existe aussi des outils permettant d&amp;#8217;optimiser le code Javascript au maximum. Ces solutions ne doivent être mises en place que lors de l&amp;#8217;utilisation de l&amp;#8217;application en production, car le code devient généralement illisible et impossible à comprendre.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;optimisation passe aussi évidemment par la gestion des calculs. Il est donc primordial de limiter les manipulations lourdes du DOM très coûteuses pour le navigateur. Une politique de mise en cache doit aussi être définie sur le serveur et avec le navigateur, grâce aux en-têtes HTTP notamment.&lt;/p&gt;
&lt;p&gt;Gardez en mémoire qu&amp;#8217;à chaque appel au serveur des opérations qui risquent d&amp;#8217;être superflues sont effectuées, comme le rechargement de certains objets voire même de requêtes coûteuses à la base de données.&lt;/p&gt;
&lt;p&gt;Enfin, les navigateurs actuels ont généralement des soucis de fuites de mémoire, en particulier lors de l&amp;#8217;utilisation de l&amp;#8217;API DOM. Une fuite de mémoire est la conséquence d&amp;#8217;un maintien en mémoire inutile de certaines variables qui ne sont plus référencées. Une extension pour Firefox appelée Leak Monitor (&lt;a href=&quot;http://addons.mozilla.org/firefox/2490&quot;&gt;http://addons.mozilla.org/firefox/2490&lt;/a&gt;) très pratique permet de les détecter. Généralement ces problèmes sont dus à des écouteurs d&amp;#8217;évènements persistants, il suffit alors la plupart du temps de leur affecter une valeur nulle, par exemple en effectuant &lt;code&gt;monElement.onclick = null;&lt;/code&gt; au déchargement de la page. Paradoxalement il faudra donc surcharger l&amp;#8217;évènement &lt;code&gt;onunload&lt;/code&gt; puis éventuellement lui réaffecter une valeur nulle à la fin de son exécution.&lt;/p&gt;
&lt;h4&gt;Aspect utilisateur&amp;#160;: bonnes pratiques&lt;/h4&gt;
&lt;p&gt;Il est très important pour bien concevoir une interface de passer par une phase sur papier. N&amp;#8217;hésitez pas à prendre du temps pour faire des schémas clairs et annotés car généralement la réalisation des interfaces arrive beaucoup plus tardivement lors du développement. Guider l&amp;#8217;utilisateur en organisant intelligemment les différents éléments de l&amp;#8217;interface est essentiel afin de la rendre claire et facile à manipuler, c&amp;#8217;est pour cela que les effets visuels seront choisis avec parcimonie doivent avoir un sens précis pour le visiteur (comme les couleurs d&amp;#8217;ailleurs).&lt;/p&gt;
&lt;p&gt;Dans le but de faciliter la communication et la compréhension de votre application, il est conseillé de standardiser les messages et les explications&amp;#160;: utiliser les mots login et nom d&amp;#8217;utilisateur pour désigner la même information est une mauvaise pratique très répandue&amp;#160;! Veillez par ailleurs à être le plus clair et concis que possible.&lt;/p&gt;
&lt;h4&gt;Le comportement du navigateur&lt;/h4&gt;
&lt;p&gt;Tout internaute est habitué  à utiliser les fonctions de navigation (&amp;#8220;précédent&amp;#8221;, &amp;#8220;suivant&amp;#8221; et &amp;#8220;actualiser&amp;#8221;) ou les marque-pages, or en transformant la page avec Ajax elles perdent leur comportement normal (la page revient à son état d&amp;#8217;origine). Il faut donc pallier à ce problème grâce à certains artifices que nous allons détailler.&lt;/p&gt;
&lt;p&gt;Prévoyez des paramètres optionnels dans l&amp;#8217;URL de la page qui permettront de retrouver l&amp;#8217;état intermédiaire de la page. Imaginez une page où le texte varie en fonction d&amp;#8217;une liste déroulante, il faudra ajouter un paramètre &lt;code&gt;text&lt;/code&gt; contenant l&amp;#8217;identifiant du paragraphe que l&amp;#8217;utilisateur souhaite retrouver. On affichera alors un lien intitulé &amp;#8220;Lien direct vers cette page&amp;#8221;, par exemple, qui évoluera à chaque changement de liste déroulante (par exemple &lt;em&gt;page.php?text=2&lt;/em&gt;). Dans le code, on testera la présence où non de ce paramètre&amp;#160;: si il existe, on modifiera la valeur par défaut de la liste déroulante et le texte affiché, sinon, on laissera la page se charger normalement. Cette solution ne permet cependant pas de tout résoudre, et un choix judicieux entre le rechargement complet de la page ou une requête avec Ajax permet de limiter les dégâts.&lt;/p&gt;
&lt;h4&gt;Accessibilité&lt;/h4&gt;
&lt;p&gt;Ajax est les applications riches sont généralement sources de problèmes d&amp;#8217;accessibilité. Plusieurs règles sont à adopter pour permettre à un maximum de visiteurs de pouvoir consulter le site conçu.&lt;/p&gt;
&lt;p&gt;N&amp;#8217;hésitez pas à préciser du contenu invisible destiné aux lecteurs d&amp;#8217;écran, par exemple, placez une balise &lt;code&gt;&amp;lt;span class=&quot;accessible&quot;&amp;gt;Début/Fin de listing de code PHP&amp;lt;/span&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt; aux deux extrémités d&amp;#8217;un listing de code, ou d&amp;#8217;autres éléments habituellement repérables par une modification de la présentation. Il vous suffira de préciser que les éléments &lt;code&gt;&quot;accessible&quot;&lt;/code&gt; ne doivent pas être affichés sur une sortie classique depuis les feuilles CSS. Pensez aussi à mettre quelques raccourcis en haut de
page, menant directement au menu, à la recherche et au contenu du site&amp;#160;: les utilisateurs de navigateurs mobiles apprécieront. Pour finir, lorsque vous utilisez des formulaires dans vos applications, utilisez les balises d&amp;#8217;organisation telles que &lt;code&gt;&amp;lt;fieldset&amp;gt;&lt;/code&gt;,
&lt;code&gt;&amp;lt;legend&amp;gt;&lt;/code&gt; ou encore &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt;, et les attributs comme &lt;code&gt;accesskey&lt;/code&gt; pour proposer des raccourcis claviers à l&amp;#8217;utilisateur. Le listing suivant montre un exemple d&amp;#8217;utilisation de ces balises.&lt;/p&gt;
&lt;pre class=&quot;xhtml sourcecode xhtml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/form.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;form&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login_form&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;action&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;page&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/fieldset.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/legend.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;Identification&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/legend.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/label.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;label&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Identifiant&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/label.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/input.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;input&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;maxlength&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;15&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/fieldset.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/fieldset.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/legend.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;Valider&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/legend.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;   &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/button.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;button&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login_go&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;login_go&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;accesskey&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;I&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;S'identifier &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/kbd.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;kbd&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;I&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;kbd&amp;gt;&amp;lt;&lt;span style=&quot;color: #66cc66;&quot;&gt;/&lt;/span&gt;button&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/fieldset.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/form.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Une pratique essentielle pour permettre l&amp;#8217;accessibilité d&amp;#8217;une application Ajax est appelée dégradation élégante (ou &lt;em lang=&quot;en&quot;&gt;graceful degradation&lt;/em&gt;). Elle consiste à toujours mettre en place une alternative cohérente et facile d&amp;#8217;utilisation utilisant le minimum (voire aucune) technologie qui risque de ne pas être exploitable par certains utilisateurs.&lt;/p&gt;
&lt;p&gt;Un exemple simple et courant de dégradation élégante est le code utilisé pour afficher une page dans une nouvelle fenêtre (depuis que l&amp;#8217;attribut &amp;#8220;&lt;code&gt;target&lt;/code&gt;&amp;#8221; est devenu obsolète en HTML)&amp;#160;: &lt;code&gt;&amp;lt;a href=&quot;http://www.martiusweb.net/post/mapage.php&quot;
onclick=&quot;window.open(this.href); return false;&quot;&amp;gt;Lien&amp;lt;/a&amp;gt;&lt;/code&gt;. Ici, Javascript détourne le rôle du navigateur pour traiter lui
même l&amp;#8217;évènement en ouvrant le lien voulu dans une nouvelle fenêtre, il annule l&amp;#8217;action normale de chargement de page grâce à
&lt;code&gt;return false;&lt;/code&gt;. Si l&amp;#8217;utilisateur n&amp;#8217;active pas Javascript, la page se charge tout de même normalement.&lt;/p&gt;
&lt;p&gt;Cette pratique est au coeur d&amp;#8217;une méthode de conception des applications riches proposée par Jeremy Keith (&lt;a href=&quot;http://domscripting.com/blog/display/41&quot;&gt;http://domscripting.com/blog/display/41&lt;/a&gt;) il y a deux ans&amp;#160;: Hijax. Il s&amp;#8217;agit de réfléchir à la manière d&amp;#8217;appréhender l&amp;#8217;implémentation d&amp;#8217;Ajax et dans son application. On peut la résumer grossièrement en disant qu&amp;#8217;il faut savoir dès les premières réflexions sur l&amp;#8217;architecture de l&amp;#8217;application qu&amp;#8217;Ajax sera utilisé, mais la concevoir et la faire fonctionner sans l&amp;#8217;implémenter dans un premier temps. On ajoute alors les fonctions de l&amp;#8217;interface dynamique en surcouche. On parle alors plutôt d&amp;#8217;amélioration progressive (&lt;em lang=&quot;en&quot;&gt;progressive enhencement&lt;/em&gt;).&lt;/p&gt;
&lt;h4&gt;Conclusion&lt;/h4&gt;
&lt;p&gt;Vous avez maintenant en main un bon nombre de pistes à approfondir pour concevoir des applications riches puissantes et efficaces. Gardez en tête que l&amp;#8217;utilisation d&amp;#8217;Ajax doit toujours être justifiée car c&amp;#8217;est un niveau de complexité supplémentaire et peut poser des problème à certains utilisateurs. A présent, soyez créatifs et inventifs, une nouvelle approche du web est à votre portée&amp;#160;!&lt;/p&gt;
&lt;p&gt;Pour en savoir plus&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://yansanmo.no-ip.org:8080/project/domGecko/&quot;&gt;Traduction de la documentation de DOM dans le cadre des projets Mozilla&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://developer.mozilla.org/fr/docs/AJAX&quot;&gt;Documentation Ajax dans le cadre des projets de Mozilla&lt;/a&gt;,&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.journaldunet.com/developpeur/client-web/&quot;&gt;Le journal du net vous propose de nombreuses ressources de bonne qualité sur le développement d&amp;#8217;applications riches&lt;/a&gt;,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Je vous conseille également l&amp;#8217;excellent livre &lt;em&gt;Développer pour le Web 2.0&lt;/em&gt; (Eric Van der Vlist, Danny Ayers, Erik Bruchez, Joe Fawcett, Alessandro Vernet) aux édition First Interactive - qui traite de nombreuses technologies et méthodes pour concevoir des applications Web 2.0 très puissantes.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/PHP-Solutions-%3A-Concevoir-une-application-pour-le-Web-avec-Ajax#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/PHP-Solutions-%3A-Concevoir-une-application-pour-le-Web-avec-Ajax#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/32</wfw:commentRss>
      </item>
    
  <item>
    <title>Le magazine PHP Solutions</title>
    <link>http://www.martiusweb.net/post/Le-magasine-PHP-Solutions</link>
    <guid isPermaLink="false">urn:md5:bf6ee5609e84151a44d24120b37f9ea8</guid>
    <pubDate>Thu, 30 Apr 2009 23:14:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Nos réalisations</category>
            
    <description>    &lt;p&gt;&lt;img title=&quot;Le magasine PHP Solutions, avr. 2009&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/realisations/phpsol.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Retrouvez Martin Richard, créateur de Martius Web tous les deux mois dans le magazine PHP Solutions. Au programme, découvrez des articles sur le langage PHP et ses usages&amp;#160;: Ajax, la POO, le référencement, le développement d&amp;#8217;applications pour Facebook, ou encore la sécurité sont quelques uns des sujets traités ou à paraître&amp;#160;!&lt;/p&gt;
&lt;p&gt;Pour découvrir le magazine, vous abonner ou trouver un point de vente, consultez &lt;a href=&quot;http://www.phpsolmag.org&quot; hreflang=&quot;fr&quot;&gt;le site internet de PHP Solutions&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>PhotoMagnet : aimants personnalisés à commander en ligne</title>
    <link>http://www.martiusweb.net/post/PhotoMagnet-%3A-aimants-personnalis%C3%A9s-%C3%A0-commander-en-ligne</link>
    <guid isPermaLink="false">urn:md5:66104975278fc148bd636f83def16516</guid>
    <pubDate>Thu, 30 Apr 2009 22:20:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Nos réalisations</category>
            
    <description>    &lt;p style=&quot;text-align:center;&quot;&gt;&lt;a href=&quot;http://www.photomagnet.fr/&quot; hreflang=&quot;fr&quot; onclick=&quot;window.open(this.href); return false;&quot; title=&quot;Visiter Photomagnet.fr&quot;&gt;&lt;img title=&quot;Le site internet Photomagnet.fr&quot; alt=&quot;Capture d'écran du site internet photomagnet.fr&quot; src=&quot;http://www.martiusweb.net/public/realisations/photomagnet.png&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;PhotoMagnet vous propose de créer vos aimants grâce à l&amp;#8217;éditeur en ligne et de les commander pour les coller partout&amp;#160;!&lt;/p&gt;
&lt;p&gt;Entièrement réalisé en PHP, le site internet utilise des technologies telles qu&amp;#8217;Ajax. Nous avons réalisé la totalité du site internet, sa charte graphique et son hébergement sur un serveur dédié.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.photomagnet.fr/&quot; hreflang=&quot;fr&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;Visiter le site internet de PhotoMagnet&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
      </item>
    
  <item>
    <title>Bienvenue sur la béta de Martius Web version 2 !</title>
    <link>http://www.martiusweb.net/post/Bienvenue-sur-la-b%C3%A9ta-de-Martius-Web-version-2-%21</link>
    <guid isPermaLink="false">urn:md5:b03a4661782879511d7a736666ecff3c</guid>
    <pubDate>Thu, 30 Apr 2009 21:10:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Actualités de Martius Web</category>
            
    <description>&lt;p&gt;Chère amie, cher ami,&lt;/p&gt;
&lt;p&gt;J&amp;#8217;ai le grand plaisir de vous accueillir sur cette page, ce qui
témoigne de l&amp;#8217;intérêt que vous portez à Martius Web, merci beaucoup&amp;#160;!&lt;/p&gt;
&lt;p&gt;Cette version est actuellement en travaux, vous trouverez des liens
morts, des bugs, des fautes d&amp;#8217;orthographe est des coquilles. N&amp;#8217;hésitez
pas à utiliser les commentaires de &lt;a href=&quot;http://www.martiusweb.net/post/Bienvenue-sur-la-b%C3%A9ta-de-Martius-Web-version-2-%21&quot;&gt;cette page&lt;/a&gt; pour me les signaler&amp;#160;!&lt;/p&gt;    &lt;p&gt;Je serais ravi d&amp;#8217;accueillir toutes vos remarques, sur la forme, le contenu du site, son organisation, alors n&amp;#8217;hésitez pas&amp;#160;!&lt;/p&gt;
&lt;p&gt;Vous pouvez transmettre l&amp;#8217;accès à vos contacts, j&amp;#8217;espère qu&amp;#8217;un maximum de monde se prendra au jeu et participera à la naissance de ce site.&lt;/p&gt;
&lt;p&gt;Bonne visite&amp;#160;!&lt;br /&gt;Martin&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Bienvenue-sur-la-b%C3%A9ta-de-Martius-Web-version-2-%21#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Bienvenue-sur-la-b%C3%A9ta-de-Martius-Web-version-2-%21#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/27</wfw:commentRss>
      </item>
    
  <item>
    <title>L'URL Rewrinting avec Apache, pour de belles adresses</title>
    <link>http://www.martiusweb.net/post/L-URL-Rewrinting-avec-Apache-pour-de-belles-adresses</link>
    <guid isPermaLink="false">urn:md5:b021e9627e4971c76e2241fe86029356</guid>
    <pubDate>Thu, 30 Apr 2009 17:50:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>Gestion d'un serveur Web</category>
        <category>accessibilité</category><category>Apache</category><category>lien hypertexte</category><category>référencement</category><category>SEO</category><category>Url Rewriting</category>    
    <description>&lt;p&gt;Le serveur web Apache propose un module d&amp;#8217;URL Rewriting, qui permet de créer des adresses virtuelles afin de masquer les URL complexes des pages web dynamiques. &lt;/p&gt;    &lt;p&gt;Le module URL Rewriting n&amp;#8217;est pas activé par défaut avec Apache. Dans le cas d&amp;#8217;un hébergement mutualisé, c&amp;#8217;est le prestataire qui décide de sa disponibilité. Si au contraire, vous êtes maître de votre installation, vous pouvez vous en charger vous même.&lt;/p&gt;
&lt;h3&gt;Installation du module&lt;/h3&gt;
&lt;p&gt;La procédure d&amp;#8217;installation et d&amp;#8217;activation du module est assez semblable selon votre installation (système d&amp;#8217;exploitation, paquets de la distribution ou compilation manuelle, &amp;#8230;).&lt;/p&gt;
&lt;p&gt;Ces modifications s&amp;#8217;appliquent dans le fichier de configuration d&amp;#8217;apache, généralement &lt;code&gt;httpd.conf&lt;/code&gt;, ou &lt;code&gt;apache*.conf&lt;/code&gt; (où * peut correspondre à la version installée).&lt;/p&gt;
&lt;p&gt;La plupart du temps, il suffit de rendre actives les lignes suivantes, en supprimant le caractère &lt;code&gt;#&lt;/code&gt; en début de ligne&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;LoadModule&lt;/span&gt; rewrite_module modules/mod_rewrite.so&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;AddModule&lt;/span&gt; mod_rewrite.c&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Si vous ne les trouvez pas, il est possible que les modules soient localisés dans un autre répertoire que &lt;code&gt;module/&lt;/code&gt; sur votre installation&amp;#160;: vérifiez ce point, sinon ajoutez-les, tout simplement&amp;#160;!&lt;/p&gt;
&lt;p&gt;Si vous avez compilé Apache par vous même, vous aurez peut-être à reprendre cette installation en ajoutant le paramètre &lt;code&gt;--enable-rewrite&lt;/code&gt; (ou &lt;code&gt;--enable-rewrite=shared&lt;/code&gt;) lors de l&amp;#8217;étape de configuration.&lt;/p&gt;
&lt;p&gt;Enfin, vous devrez recharger apache, généralement avec l&amp;#8217;une de ces commandes&amp;#160;: &lt;code&gt;apache2 -k restart&lt;/code&gt;, &lt;code&gt;apachectl -k restart&lt;/code&gt;, ou encore &lt;code&gt;/etc/init.d/apache restart&lt;/code&gt;. Sous windows, il vous suffira d&amp;#8217;utiliser les raccourcis graphiques.&lt;/p&gt;
&lt;h3&gt;Un premier test&lt;/h3&gt;
&lt;p&gt;Généralement, les règles de modification des URLs sont placées dans un fichier &lt;code&gt;.htaccess&lt;/code&gt; (pour une installation standard), qui permet d&amp;#8217;ajouter des directives qu&amp;#8217;Apache appliquera au répertoire dans lequel se trouve le fichier.&lt;/p&gt;
&lt;p&gt;Créez un fichier .htaccess à la racine de votre site internet et placez-y ces quelques lignes&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;lt;IfModule mod_rewrite.c&amp;gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #00007f;&quot;&gt;RewriteEngine&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;On&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; ceci_est_un_test /index.html&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&amp;lt;/IfModule&amp;gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Ces lignes auront normalement pour effet d&amp;#8217;afficher la page d&amp;#8217;accueil (&lt;code&gt;index.html&lt;/code&gt;) si vous essayer d&amp;#8217;afficher &lt;code&gt;ceci_est_un_test&lt;/code&gt;. Essayons maintenant de comprendre ces quelques lignes&amp;#8230;&lt;/p&gt;
&lt;p&gt;La condition &lt;code&gt;&amp;lt;IfModule mod_rewrite.c&amp;gt;&lt;/code&gt; indique à Apache qu&amp;#8217;il doit vérifier que le module est disponible avant de tenter d&amp;#8217;appliquer les règles placées entre les deux balises. La directive &lt;code&gt;RewriteEngine On&lt;/code&gt; permet d&amp;#8217;indiquer que le module Url Rewriting doit être activé pour ce répertoire. Enfin, la directive &lt;code&gt;RewriteRule&lt;/code&gt; sert à enregistrer une règle de conversion d&amp;#8217;URL. La chaine de caractères avant l&amp;#8217;espace indique le format de l&amp;#8217;url recherchée, l&amp;#8217;autre indique l&amp;#8217;adresse réellement sur le serveur.&lt;/p&gt;
&lt;p&gt;Ces règles sont définies à l&amp;#8217;aide de la syntaxe des expressions régulières.&lt;/p&gt;
&lt;h3&gt;Les règles&lt;/h3&gt;
&lt;p&gt;Les expressions régulières permettent de rechercher des chaines de caractères variables.&lt;/p&gt;
&lt;h4&gt;Caractères spéciaux&lt;/h4&gt;
&lt;p&gt;Certains caractères des expressions régulières portent un sens particulier&amp;#160;:
&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;^&lt;/code&gt;&amp;#160;: indique que nous sommes en début de ligne, ou au début de la chaîne de
caractères. Cependant, entre crochets, la signification est différente,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$&lt;/code&gt;&amp;#160;: indique lui que nous sommes en fin de ligne, ou de chaîne,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.&lt;/code&gt;&amp;#160;: remplace tout caractère inconnu,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\&lt;/code&gt;&amp;#160;: échape un caractère utilisé dans la syntaxe regex. Par exemple, pour utiliser
un point, la syntaxe est &lt;code&gt;\.&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ainsi, pour rechercher la chaine &lt;code&gt;index.html&lt;/code&gt;, l&amp;#8217;expression régulière à utiliser est &lt;code&gt;^index\.html$&lt;/code&gt;, Apache n&amp;#8217;appliquera alors pas la règle si l&amp;#8217;adresse demandée est &lt;code&gt;quelquechose-index.html&lt;/code&gt; ou encore &lt;code&gt;index.html-autrechose&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;Les classes de caractères&lt;/h4&gt;
&lt;p&gt;Les classes de caractères servent à rechercher un des caractères parmi un ensemble, une classe s&amp;#8217;écrit entre crochets. Voici quelques exemples de classes&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;[éèê]&lt;/code&gt;&amp;#160;: signifie que l&amp;#8217;on cherche le caractère é, ou è ou encore ê,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[a-z]&lt;/code&gt;&amp;#160;: signifie que l&amp;#8217;on cherche n&amp;#8217;importe quelle lettre en minuscules,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[a-zA-Z]&lt;/code&gt;&amp;#160;: signifie que l&amp;#8217;on cherche n&amp;#8217;importe quelle lettre, il est possible de faire des combinaisons plus plus personnelles, par exemple &lt;code&gt;[a-gA-Gn-zN-Z]&lt;/code&gt; signifie que l&amp;#8217;on cherche une lettre comprise entre a et g et entre n et z,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[0-9]&lt;/code&gt;&amp;#160;: signifie donc que l&amp;#8217;on cherche un chiffre,&lt;/li&gt;
&lt;li&gt;enfin, il est possible de rechercher n&amp;#8217;importe quel caractère &lt;em&gt;sauf&lt;/em&gt; certains en ajoutant le caractère &lt;code&gt;^&lt;/code&gt; en début de classe&amp;#160;: &lt;code&gt;[^a-zA-Z]&lt;/code&gt; signifie que l&amp;#8217;on recherche tout caractère n&amp;#8217;étant pas une lettre.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Les captures&lt;/h4&gt;
&lt;p&gt;Vous pouvez avoir besoin de réutiliser certaines informations de l&amp;#8217;adresse recherchée pour indiquer l&amp;#8217;adresse réelle de votre page, par exemple, pour remplacer &lt;code&gt;glossaire-a.html&lt;/code&gt; en &lt;code&gt;glossaire.php?lettre=a&lt;/code&gt;. on utilise alors les parenthèses de capture &lt;code&gt;()&lt;/code&gt;. Ainsi, chaque extrait de la chaine trouvée entre &lt;code&gt;()&lt;/code&gt; pourra être utilisée dans l&amp;#8217;adresse de remplacement avec une variable numérotée &lt;code&gt;$n&lt;/code&gt; (où n correspond au numéro de la capture).&lt;/p&gt;
&lt;p&gt;Par exemple&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; ^glossaire-&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;a-z&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;\.html$ glossaire.php?lettre=$&lt;span style=&quot;color: #ff0000;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;h4&gt;Les quantificateurs&lt;/h4&gt;
&lt;p&gt;Les quantificateurs permettent d&amp;#8217;indiquer la répétition d&amp;#8217;un caractère, c&amp;#8217;est à dire le nombre de fois où on souhaite les retrouver.&lt;/p&gt;
&lt;p&gt;Voici les principaux quantificateurs&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;?&lt;/code&gt;&amp;#160;: 0 ou 1 caractère (c&amp;#8217;est à dire que le caractère n&amp;#8217;est pas obligatoire),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;*&lt;/code&gt;&amp;#160;: 0 ou plusieurs caractères (le caractère peut ne pas être trouvé ou trouvé un nombre infini de fois à la suite),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;+&lt;/code&gt;&amp;#160;: 1 ou plusieurs caractères (le caractère doit être trouvé, mais le nombre de fois à la suite n&amp;#8217;a pas d&amp;#8217;importance),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{n}&lt;/code&gt;&amp;#160;: le caractère doit être trouvé exactement &lt;code&gt;n&lt;/code&gt; fois,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{n,m}&lt;/code&gt;&amp;#160;: le caractère doit être trouvé entre &lt;code&gt;n&lt;/code&gt; et &lt;code&gt;m&lt;/code&gt; fois,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{n,}&lt;/code&gt;&amp;#160;: le caractère doit être trouvé &lt;code&gt;n&lt;/code&gt; fois ou plus.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Voici quelques exemples d&amp;#8217;utilisation&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;index\.html?&lt;/code&gt;&amp;#160;: on recherche &lt;code&gt;index.htm&lt;/code&gt; ou &lt;code&gt;index.html&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;.+\.html$&lt;/code&gt;&amp;#160;: on recherche n&amp;#8217;importe quelle adresse dont l&amp;#8217;extension est .html,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;glossaire-[a-z]+\.html&lt;/code&gt;&amp;#160;: cette fois, notre adresse peut être utilisées pour plusieurs lettres (par exemple, &lt;code&gt;glossaire-aa.html&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;L&amp;#8217;alternative&lt;/h4&gt;
&lt;p&gt;Le dernier caractère dont nous allons parler est &lt;code&gt;|&lt;/code&gt;, il signifie &amp;#8220;ou&amp;#8221; quand il est utiliser à l&amp;#8217;intérieur d&amp;#8217;une capture, par exemple &lt;code&gt;(index|home|accueil)\.html&lt;/code&gt; permet de rechercher &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;home.html&lt;/code&gt; ou &lt;code&gt;accueil.html&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Les réécritures conditionnelles&lt;/h3&gt;
&lt;p&gt;La réécriture conditionnelle permet de limiter le cas dans lesquels s&amp;#8217;appliquent certaines règles. Vous pouvez utiliser une réécriture conditionnelle pour interdire l&amp;#8217;utilisation d&amp;#8217;images enregistrées sur votre serveur depuis d&amp;#8217;autres pages, ou vérifier d&amp;#8217;abord si la page existe rééllement avant d&amp;#8217;essayer de transformer l&amp;#8217;adresse.&lt;/p&gt;
&lt;p&gt;La directive d&amp;#8217;Apache à utiliser est &lt;code&gt;RewriteCond&lt;/code&gt;, vous devrez généralement effectuer des tests sur les variables d&amp;#8217;environnement d&amp;#8217;apache, par exemple &lt;code&gt;%{REQUEST_FILENAME}&lt;/code&gt; pour tester l&amp;#8217;adresse demandée.&lt;/p&gt;
&lt;p&gt;Voici comment tester l&amp;#8217;existance du fichier avant de rediriger&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteCond&lt;/span&gt; %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;REQUEST_FILENAME&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; !-f&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteCond&lt;/span&gt; %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;REQUEST_FILENAME&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; !-d &lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;.+&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;\.html$ index.php?page=$&lt;span style=&quot;color: #ff0000;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Voici quelques autres exemples d&amp;#8217;utilisation&amp;#160;:&lt;/p&gt;
&lt;p&gt;Ici, l&amp;#8217;adresse IP 127.0.0.1 sera, quelque soit l&amp;#8217;adresse tapée (.*) redirigé vers inderdit.html.&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteCond&lt;/span&gt; %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;REMOTE_ADDR&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ^127.0.0.1$&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; .* /interdit.html&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;On peut rediriger les utilisateurs d&amp;#8217;internet explorer vers le site de Mozilla&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteCond&lt;/span&gt; %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;HTTP_USER_AGENT&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; MSIE&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; .* http://www.mozilla.org&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Ou encore interdire le hot linking, c&amp;#8217;est à dire, l&amp;#8217;utilisation d&amp;#8217;images hébergées sur votre site depuis un autre&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteCond&lt;/span&gt; %&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;HTTP_HOST&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;^&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;http://www.martiusweb.net&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;.+&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;\.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;jpg|gif|png&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;^ /interdit.$&lt;span style=&quot;color: #ff0000;&quot;&gt;1&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;h3&gt;Les drapeaux&lt;/h3&gt;
&lt;p&gt;Les drapeaux permettent de modifier partiellement le comportement d&amp;#8217;une directive d&amp;#8217;Apache. Un drapeau est placé entre crochets à la fin d&amp;#8217;une directive. Vous pouvez cumuler les drapeaux en les séparant par des virgules.&lt;/p&gt;
&lt;p&gt;Voici la liste des principaux drapeaux&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;NC&lt;/code&gt;&amp;#160;: permet de rendre la règle insensible à la casse (c&amp;#8217;est à dire qu&amp;#8217;aucune différence ne sera faite entre les minuscules et les majuscules),&lt;/p&gt;
&lt;p&gt;&lt;code&gt;L&lt;/code&gt;&amp;#160;: permet d&amp;#8217;indiquer à Apache que la règle appliquée est la dernière. En effet, tant que Apache ne rencontrera pas ce drapeau, il tentera de réécrire à nouveau l&amp;#8217;adresse obtenue. Par exemple&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; accueil\.html$ accueil.php&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; accueil\.php$ index.php?page=accueil&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;En demandant l&amp;#8217;adresse &lt;code&gt;accueil.html&lt;/code&gt;, celle-ci sera réécrite deux fois. Elle sera en premier transformée en &lt;code&gt;accueil.php&lt;/code&gt;, puis en &lt;code&gt;index.php?page=accueil&lt;/code&gt;. Pour interdire la deuxième réécriture, vous ajouterez le drapeau &lt;code&gt;[L]&lt;/code&gt; à la fin de la première règle&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; accueil\.html$ accueil.php &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;L&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; accueil\.php$ index.php?page=accueil&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;G&lt;/code&gt;&amp;#160;: Permet d&amp;#8217;indiquer que la page n&amp;#8217;est définitivement plus disponible (&lt;em lang=&quot;en&quot;&gt;gone&lt;/em&gt;), ceci correspond au statut HTTP 410,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;F&lt;/code&gt;&amp;#160;: envoie le statut HTTP 403 indiquant que l&amp;#8217;accès à la page est interdit,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;R&lt;/code&gt; ou &lt;code&gt;R=n&lt;/code&gt;&amp;#160;: envoie le code statut HTTP n, par exemple, pour indiquer qu&amp;#8217;une page à changé d&amp;#8217;adresse, vous pouvez écrire une règle comme celle-ci&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;apache sourcecode Apache&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;RewriteRule&lt;/span&gt; article_urlrewriting.html$ /post/Url-Rewriting &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;R=&lt;span style=&quot;color: #ff0000;&quot;&gt;301&lt;/span&gt;,L&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;N&lt;/code&gt;&amp;#160;: Apache reprendra l&amp;#8217;analyse de l&amp;#8217;adresse depuis le début, en utilisant la dernière adresse transformée obtenue. Attention, l&amp;#8217;utilisation de ce drapeau peut causer une boucle infinie (une règle dirigeant Apache vers une autre et vice-versa, pensez alors à utiliser le drapeau &lt;code&gt;L&lt;/code&gt;),&lt;/p&gt;
&lt;p&gt;&lt;code&gt;C&lt;/code&gt;&amp;#160;: lorsqu&amp;#8217;une règle comportant ce drapeau est vérifiée, apache analysera l&amp;#8217;adresse transformée avec la requête suivante, si celle-ci possède également ce drapeau, si la règle n&amp;#8217;est pas vérifiée, Apache passera à la première règle suivante ne comportant pas se drapeau.&lt;/p&gt;
&lt;h3&gt;Adresse de base&lt;/h3&gt;
&lt;p&gt;Dans certains cas, il peut être nécessaire de préciser à Apache le répertoire de base dans lequel nous travaillons à l&amp;#8217;aide de la directive &lt;code&gt;RewriteBase&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;L&amp;#8217;utilisation des règles de réécriture d&amp;#8217;URL permettent d&amp;#8217;améliorer le référencement de vos pages par les moteurs de recherche ou encore la mémorisation par le visiteur, qui pourra comprendre plus facilement l&amp;#8217;adresse.&lt;/p&gt;
&lt;p&gt;Pour en savoir plus sur les expressions régulières, je vous invite à consulter le &lt;a hreflang=&quot;fr&quot; href=&quot;http://fr2.php.net/manual/fr/reference.pcre.pattern.syntax.php&quot;&gt;manuel de PHP qui offre une introduction à la syntaxe des expressions régulière&lt;/a&gt; très complète.&lt;/p&gt;
&lt;p&gt;Pour en savoir plus sur le module URL Rewriting d&amp;#8217;Apache, consultez &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.apachefrance.com/Manuels/Apache_1.3_VF/mod/mod_rewrite.html#RewriteBase&quot;&gt;la page de manuel à ce sujet&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/L-URL-Rewrinting-avec-Apache-pour-de-belles-adresses#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/L-URL-Rewrinting-avec-Apache-pour-de-belles-adresses#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/26</wfw:commentRss>
      </item>
    
  <item>
    <title>19# Jouer avec les fonds</title>
    <link>http://www.martiusweb.net/post/19-Jouer-avec-les-fonds</link>
    <guid isPermaLink="false">urn:md5:2fe4738f208b19c93ed2791baf9558d2</guid>
    <pubDate>Tue, 28 Apr 2009 23:30:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>XHTML et CSS en quelques heures (2e version)</category>
        <category>balises</category><category>block</category><category>création de sites web</category><category>css</category><category>intégrateur</category><category>optimisation</category><category>styles</category><category>web design</category>    
    <description>&lt;p&gt;Il est possible d&amp;#8217;utiliser les propriétés de positionnement et de répétition des fonds pour réaliser des effets graphiques sympathiques et optimisés.&lt;/p&gt;    &lt;p&gt;Sur cette page&amp;#160;:&lt;/p&gt;
&lt;h3&gt;19.1# Les propriétés de répétition&lt;/h3&gt;
&lt;p&gt;Nous l&amp;#8217;avons vu dans &lt;a href=&quot;http://www.martiusweb.net/post/Les-blocs&quot;&gt;le chapitre précédent&lt;/a&gt;, il existe une propriété appelée &lt;code&gt;background-repeat&lt;/code&gt;, qui permet de gérer la manière dont le fond d&amp;#8217;un boc sera géré en fonction de sa taille. Rappelons rapidement son fonctionnement&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;background-repeat: no-repeat;&lt;/code&gt; permet d&amp;#8217;interdire l&amp;#8217;utilisation du fond comme une mosaïque, si la taille de l&amp;#8217;image est inférieure à celle du bloc, elle ne sera donc affichée qu&amp;#8217;une fois,&lt;/li&gt;
&lt;li&gt;il existe naturellement le comportement inverse, choisi par défaut&amp;#160;: &lt;code&gt;background-repeat: repeat;&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;background-repeat: repeat-x;&lt;/code&gt; indique que le fond sera répété sur un axe horizontal (les abscisses) uniquement,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;background-repeat: repeat-y;&lt;/code&gt; signifie, à l&amp;#8217;inverse, que le fond ne sera répété que sur un axe vertical (les ordonnées).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cette propriété peut être très intéressante pour réaliser certains effets sur des fonds, quand ceux-ci représentent des motifs ou des dégradés&amp;#160;: il est en effet possible de couvrir la totalité d&amp;#8217;un bloc grâce à une image de quelques pixels seulement. D&amp;#8217;ailleurs, plusieurs sites internet vous proposent de générer automatiquement ces motifs prêts à être utilisés comme mosaïques.&lt;/p&gt;
&lt;p&gt;Le site &lt;a hreflang=&quot;en&quot; href=&quot;http://www.bgpatterns.com/&quot;&gt;Background patterns&lt;/a&gt; est l&amp;#8217;un d&amp;#8217;eux (il est en anglais, mais très facile à utiliser&amp;#160;!). Nous allons utiliser un motif généré depuis ce site internet pour l&amp;#8217;exemple&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;img title=&quot;Motif utilisable en mosaïque comme fond de bloc&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/post/../public/cours-xhtml/pattern.jpg&quot; /&gt;&lt;/p&gt;
&lt;p&gt;l&amp;#8217;appliquer comme fond est un jeu d&amp;#8217;enfant&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;xhtml sourcecode xhtml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/div.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;patternized&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/p.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;Ceci est un bloc avec un joli motif !&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/p.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/div.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #6666ff;&quot;&gt;.patternized&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/pattern.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;white&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* on affiche le texte en blanc... pour le rendre lisible ! */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Le résultat obtenu sera donc&amp;#160;:&lt;/p&gt;
&lt;div style=&quot;background: transparent url(/public/cours-xhtml/pattern.jpg) repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; color: white; width: 300px; height: 200px;&quot;&gt;&lt;p&gt;Ceci est un bloc avec un joli motif&amp;#160;!&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;L&amp;#8217;exemple ici est assez sommaire, mais je vous invite à consulter l&amp;#8217;&lt;a hreflang=&quot;en&quot; href=&quot;http://www.smashingmagazine.com/2008/07/09/textures-and-patterns-design-showcase/&quot;&gt;article à ce sujet sur le blog de Smashing Magazine&lt;/a&gt;, qui présente de nombreux exemples d&amp;#8217;utilisation de motifs vraiment sympathiques.&lt;/p&gt;
&lt;p&gt;Il est possible, dans certains cas, d&amp;#8217;optimiser Prenons un autre exemple plus local, au hasard&amp;#8230; le fond de l&amp;#8217;en-tête du site, mais si, celui là&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.martiusweb.net/public/cours-xhtml/fondmsw.png&quot;&gt;&lt;img title=&quot;En-tête de Martius Web&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/.fondmsw_m.jpg&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Pour réaliser le fond bleu-ciel avec un petit dégradé, j&amp;#8217;ai simplement découpé l&amp;#8217;image en gardant sa hauteur d&amp;#8217;origine et en réduisant sa largeur au minimum&amp;#160;: ici, une largeur d&amp;#8217;un pixel suffit&amp;#160;! L&amp;#8217;image utilisée est donc&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://www.martiusweb.net/themes/martiusweb/images/head/bg.png&quot; alt=&quot;L'image de fond de l'en-tête de Martius Web&quot; style=&quot;width: 10px; height: 112px;&quot; /&gt; L&amp;#8217;image est ici élargie à 10 pixels pour rester visible&amp;#160;!&lt;/p&gt;
&lt;p&gt;Vous connaissez déjà le résultat obtenu, nous allons donc nous intéresser au code&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;xhtml sourcecode xhtml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/div.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;div&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000066;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;head&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Martius Web&lt;span style=&quot;color: #009900;&quot;&gt;&lt;a href=&quot;http://giminik.developpez.com/xhtml/div.html&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #cc00cc;&quot;&gt;#head&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/head/bg.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-repeat&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;repeat-x&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;&lt;span style=&quot;color: #933;&quot;&gt;100&lt;/span&gt;%&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;112px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Rien de très difficile à comprendre, on choisit simplement de forcer la hauteur du bloc à 112 pixels pour que l&amp;#8217;image soit intégralement affichée, mais dans un bloc donc le contenu dépasse cette hauteur, il devient inutile de préciser cette propriété. On peut, éventuellement, la remplacer par &lt;code&gt;min-height&lt;/code&gt;, bien que celle-ci ne soit pas supportée par Internet Explorer avant la version 7.&lt;/p&gt;
&lt;p&gt;L&amp;#8217;opération est assez similaire pour répéter un motif sur la hauteur, je vous invite à tester cet effet par vous même pour bien assimiler son fonctionnement&amp;#160;!&lt;/p&gt;
&lt;h3&gt;19.2# Changer de fond sans recharger l&amp;#8217;image lors d&amp;#8217;un survol&lt;/h3&gt;
&lt;p&gt;On peut également optimiser l&amp;#8217;utilisation des images sur notre site en utilisant les propriétés de positionnement des fonds.&lt;/p&gt;
&lt;p&gt;Pour réaliser un bouton dont le fond change lors du passage de la souris on pourrait utiliser les deux images suivantes&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/sprites-separated_01.png&quot; /&gt; (button_normal.png) et &lt;img alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/sprites-separated_02.png&quot; /&gt; (button_active.png) lors du survol de la souris.&lt;/p&gt;
&lt;p&gt;On pourra utiliser les styles css suivants pour réalisé l&amp;#8217;effet voulu&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #cc00cc;&quot;&gt;#menu&lt;/span&gt; a&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/button_normal.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;100px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;25px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;padding-top&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;5px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;text-align&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;center&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #cc00cc;&quot;&gt;#menu&lt;/span&gt; a&lt;span style=&quot;color: #3333ff;&quot;&gt;:hover&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/button_active.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #cc00cc;&quot;&gt;#FEFEFE&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Vous imaginez le résultat&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;javascript:void(0);&quot; class=&quot;tuto-css-no-sprite&quot;&gt;test&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Vous pouvez me croire sur parole ou regarder la capture d&amp;#8217;écran ci-dessous&amp;#160;; lors de l&amp;#8217;affichage d&amp;#8217;une page web, l&amp;#8217;opération la plus longue est souvent le traitement de la requête HTTP par le serveur, c&amp;#8217;est à dire l&amp;#8217;attente et la réception du contenu de la page. Pour chaque image sur votre page, il faudra compter une requête. Minimiser leur nombre est probablement le meilleur moyen d&amp;#8217;optimiser la vitesse d&amp;#8217;affichage de votre site internet.&lt;/p&gt;
&lt;p&gt;&lt;img title=&quot;Vitesse d'affichage d'une page avec Firefox 3.5&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/speed.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Il devient alors très intéressant d&amp;#8217;utiliser une seule image pour le fond du bouton, et c&amp;#8217;est d&amp;#8217;autant plus vrai qu&amp;#8217;il est possible de conserver l&amp;#8217;effet interactif souhaité&amp;#160;!&lt;/p&gt;
&lt;p&gt;Dans notre exemple, les dimensions d&amp;#8217;un bouton sont 100px par 30px. nous pouvons utiliser une image de 100px par 60px qui contient les deux fonds&amp;#160;:&lt;/p&gt;
&lt;p&gt;&lt;img title=&quot;Image contenant les deux fonds&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/sprite.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;img title=&quot;Position des fonds&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/sprite-position.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Nous pourrons reproduire l&amp;#8217;effet grâce à cette feuille de styles&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #cc00cc;&quot;&gt;#menu&lt;/span&gt; a&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/button.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;100px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;height&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;25px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;padding-top&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;5px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;text-align&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;center&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #cc00cc;&quot;&gt;#menu&lt;/span&gt; a&lt;span style=&quot;color: #3333ff;&quot;&gt;:hover&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'images/button.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; -&lt;span style=&quot;color: #933;&quot;&gt;30px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #cc00cc;&quot;&gt;#FEFEFE&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Nous utilisons les propriétés de positionnement du fond en CSS, en plaçant l&amp;#8217;image 30 pixels au dessus de la zone visible (-30px), occasionnant l&amp;#8217;affichage des 30 derniers pixels de l&amp;#8217;image comme fond du bouton. Il est également possible de décaler l&amp;#8217;image sur un axe horizontal, avec une image représentant une mosaïque d&amp;#8217;icônes.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/sprite-visible.png&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/19-Jouer-avec-les-fonds#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/19-Jouer-avec-les-fonds#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/47</wfw:commentRss>
      </item>
    
  <item>
    <title>Complément# Modèle des blocs W3C et Quirks mode</title>
    <link>http://www.martiusweb.net/post/Modele-des-blocs-W3C-et-Quirks-mode</link>
    <guid isPermaLink="false">urn:md5:af6bfb5f72a84c956646a4a6c1a668fb</guid>
    <pubDate>Tue, 28 Apr 2009 23:29:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>XHTML et CSS en quelques heures (2e version)</category>
        <category>block</category><category>création de sites web</category><category>css</category><category>quirks mode</category><category>web design</category><category>xhtml</category>    
    <description>&lt;p&gt;Internet explorer a introduit sa propre méthode pour gérer les dimensions d&amp;#8217;un bloc, qui diffère du modèle officiellement soutenu par la norme. Ainsi, dans certaines configurations, il est nécessaire d&amp;#8217;adapter votre feuille de style pour la rendre conforme sous Internet Explorer.&lt;/p&gt;    &lt;h3&gt;&lt;em&gt;Quirks mode&lt;/em&gt;, kézako&amp;#160;?&lt;/h3&gt;
&lt;p&gt;Le &lt;em&gt;quirks mode&lt;/em&gt; appelé aujourd&amp;#8217;hui en français &lt;em&gt;mode de compatibilité&lt;/em&gt; (avec Internet Explorer). Selon différents critères, une page sera affichée en respectant de manière stricte les conventions établies par le W3C, ou selon des méthodes de rendu propres au navigateur. Le Quirks mode correspond à ce dernier mode de rendu.&lt;/p&gt;
&lt;p&gt;Le principal point de désaccord entre le mode strict et le Quirks mode concerne le rendu des blocs. Ces divergences datent de l&amp;#8217;époque d&amp;#8217;Internet Explorer 4 et Netscape 4, autant dire que c&amp;#8217;est le Moyen-Âge du web&amp;#160;! Au fil des nouvelles versions, Internet Explorer s&amp;#8217;est lentement rapproché des standards. Disons en fait que les développeurs ont essayé d&amp;#8217;implémenter plus correctement certains éléments, et en ont oubliés d&amp;#8217;autres. Le tir semble être enfin réajusté avec la version 8. Quand à Netscape, le navigateur a disparu au profit de Firefox, généralement bien respectueux des normes. Cependant un dilemme s&amp;#8217;est posé aux développeurs&amp;#160;: en améliorant le moteur de rendu pour se rendre conforme aux recommandations du W3C, les vieux sites internet risquaient de ne plus s&amp;#8217;afficher correctement.&lt;/p&gt;
&lt;p&gt;Un compromis fut trouvé&amp;#160;: si le concepteur de la page connait bien les standards, alors il fera l&amp;#8217;effort d&amp;#8217;indiquer qu&amp;#8217;il souhaite utiliser le mode strict, sinon, la page est affichée en Quirks mode&amp;#160;: à l&amp;#8217;ancienne. Ceci s&amp;#8217;applique sur tous les navigateurs récents.&lt;/p&gt;
&lt;h3&gt;Comment choisir le mode d&amp;#8217;affichage&amp;#160;?&lt;/h3&gt;
&lt;p&gt;En fait, il fallait utiliser un élément du langage propre aux recommandations récentes, c&amp;#8217;est pourquoi si l&amp;#8217;intégrateur utilise un &lt;em&gt;DocType&lt;/em&gt; standard, la page est affichée en mode strict. On parle de &lt;em&gt;DocType Switching&lt;/em&gt;. Si un nouveau DocType inconnu du navigateur est utilisé, cela signifie probablement que celui-ci est trop récent pour être interprété&amp;#160;: le mode strict est alors utilisé.&lt;/p&gt;
&lt;p&gt;Par ailleurs, sous internet explorer, l&amp;#8217;utilisation d&amp;#8217;un prologue XML comme celui-ci&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;xml sourcecode xml&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;iso-8859-1&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Internet Explorer 6 passera directement en mode Quirks, peut importe la DTD utilisée. Ce comportement disparait avec Internet Explorer 7.&lt;/p&gt;
&lt;p&gt;Enfin, l&amp;#8217;utilisation d&amp;#8217;un &lt;a href=&quot;http://www.martiusweb.net/post/XHTML-et-le-type-MIME&quot;&gt;type mime xml&lt;/a&gt;, obligera le navigateur à afficher la page en mode strict, cependant, Internet Explorer 6 ne supporte que le type &lt;code&gt;text/html&lt;/code&gt;, et dans les autres cas, la page sera affichée comme un fichier texte (donc le code sera visible).&lt;/p&gt;
&lt;h3&gt;&lt;em&gt;Almost Strict Mode&lt;/em&gt;, Strict&amp;#8230; mais pas tout à fait&lt;/h3&gt;
&lt;p&gt;Les standards considèrent que les images sont des éléments en ligne. Ce comportement entraine une marge inférieure indésirable qui correspond à l&amp;#8217;espace occupé en dessous de la ligne par des lettres comme le &amp;#8220;p&amp;#8221; ou le &amp;#8220;g&amp;#8221;. Pour supprimer cette marge, la seule solution consiste à considérer l&amp;#8217;élément comme un bloc à l&amp;#8217;aide de la propriété &lt;code&gt;display: block;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;La situation étant un peu confuse, le Almost Strict Mode correspond au mode strict avec une exception&amp;#160;: les image sont des blocs. Ce cas ce présente en utilisant un autre DocType que le X/HTML Strict (ou XHTML 1.1).&lt;/p&gt;
&lt;h3&gt;Les différences de rendu des blocs&lt;/h3&gt;
&lt;p&gt;La principale différence entre ces deux modes de rendu concerne donc le rendu des blocs. En effet, en Quirks mode, le navigateur considère que la valeur de les prorpriétés &lt;code&gt;width&lt;/code&gt; et &lt;code&gt;height&lt;/code&gt; correspondent à la largeur et hauteur du bloc, et donc que l&amp;#8217;on inclue la taille des marges dedans, alors que le W3C considère qu&amp;#8217;il faut ajouter à la largeur (ou la hauteur), les marges et la bordure.&lt;/p&gt;
&lt;p&gt;Pour la feuille de style suivante, l&amp;#8217;interprétation sera différente&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #6666ff;&quot;&gt;.bloc&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;250px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;12px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;padding&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;12px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;2px&lt;/span&gt; &lt;span style=&quot;color: #cc00cc;&quot;&gt;#000000&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;solid&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;&lt;img title=&quot;Différences entre le Quirks Mode et Strict Mode, juil. 2009&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/ms_w3c.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Chez microsoft, la taille de la zone de texte sera 250 - 12*2 - 12*2 - 2*2 = 200px. (il y a une bordure de chaque côté).&lt;br /&gt;Pour le W3C, on trouve que la taille du bloc sera 250+12*2 + 12*2 + 2*2.&lt;/p&gt;
&lt;p&gt;D&amp;#8217;autres différences existent, vous pouvez en prendre connaissance sur l&amp;#8217;un des sites de référence sur le support des standards &lt;a hreflang=&quot;en&quot; href=&quot;http://www.quirksmode.org/css/quirksmode.html&quot;&gt;Quirksmode&lt;/a&gt; (en anglais).&lt;/p&gt;
&lt;h3&gt; Finalement&amp;#160;?&lt;/h3&gt;
&lt;p&gt;Finalement, avec la disparition programmée d&amp;#8217;Internet Explorer 6 et l&amp;#8217;arrivée de la version 8, le Quirks Mode n&amp;#8217;a pas beaucoup d&amp;#8217;importance pour un intégrateur respectueux des standard. Cependant, il est encore un peu trop tôt pour passer ces subtilités sous silence, surtout si vous héritez du code d&amp;#8217;un vieux site.&lt;/p&gt;</description>
    
    
    
          <comments>http://www.martiusweb.net/post/Modele-des-blocs-W3C-et-Quirks-mode#comment-form</comments>
      <wfw:comment>http://www.martiusweb.net/post/Modele-des-blocs-W3C-et-Quirks-mode#comment-form</wfw:comment>
      <wfw:commentRss>http://www.martiusweb.net/feed/atom/comments/45</wfw:commentRss>
      </item>
    
  <item>
    <title>18# Les blocs</title>
    <link>http://www.martiusweb.net/post/Les-blocs</link>
    <guid isPermaLink="false">urn:md5:89d6e685e552e2f204b97146011f8e36</guid>
    <pubDate>Tue, 28 Apr 2009 23:28:00 +0200</pubDate>
    <dc:creator>Martin Richard</dc:creator>
        <category>XHTML et CSS en quelques heures (2e version)</category>
        <category>block</category><category>création de sites web</category><category>css</category><category>quirks mode</category><category>styles</category><category>xhtml</category>    
    <description>&lt;p&gt;Les blocs possèdent des propriétés de mise en forme communes, afin de personnaliser leur aspect. Nous allons les étudier avant d&amp;#8217;apprendre comment les positionner.&lt;/p&gt;    &lt;p&gt;Sur cette page&amp;#160;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#taille-d-un-bloc&quot;&gt;Taille d&amp;#8217;un bloc&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#depassement&quot;&gt;Dépassement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#bordures&quot;&gt;Bordures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#marges&quot;&gt;Marges&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#fond&quot;&gt;Fond&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.martiusweb.net/post/post/Les-blocs#conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;taille-d-un-bloc&quot;&gt;18.1# Taille d&amp;#8217;un bloc&lt;/h3&gt;
&lt;p&gt;CSS propose une série de propriétés pour définir la taille d&amp;#8217;un bloc. La largeur est définie grâce à &lt;code&gt;width&lt;/code&gt; et la hauteur grâce à &lt;code&gt;height&lt;/code&gt;. La plupart du temps, les dimensions d&amp;#8217;un bloc sont définies en pixels (ou une autre unité de longueur utilisable en CSS),en pourcentage relativement à la taille de l&amp;#8217;élément parent, ou en utilisant la valeur &lt;code&gt;auto&lt;/code&gt;, qui laissera le navigateur définir la taille en fonction du contenu.&lt;/p&gt;
&lt;p&gt;Quatre autres propriétés peuvent être utilisées pour définir la taille d&amp;#8217;un bloc&amp;#160;: &lt;code&gt;min-width&lt;/code&gt; et &lt;code&gt;min-height&lt;/code&gt; permettent de définir la taille minimale du bloc, cela signifie que si son contenu dépasse ces dimensions, alors la taille du bloc sera adaptée. De la même manière, &lt;code&gt;max-width&lt;/code&gt; et &lt;code&gt;max-height&lt;/code&gt; permettent de définir la taille maximale d&amp;#8217;un bloc. Ses dimensions seront réduites si son contenu ne dépasse pas ces dimensions, sinon, le contenu débordant sera géré en fonction de la politique de dépassement définie.&lt;/p&gt;
&lt;ul class=&quot;tuto-css-browsers-short&quot;&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Mozilla Firefox&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/ff.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Microsoft Internet Explorer&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/ie.png&quot; /&gt; &lt;code&gt;min-width&lt;/code&gt;, &lt;code&gt;min-height&lt;/code&gt;, &lt;code&gt;max-width&lt;/code&gt; et &lt;code&gt;max-height&lt;/code&gt; ne sont supportées qu&amp;#8217;à partir d&amp;#8217;internet explorer 7, avec internet explorer 6, le comportement de &lt;code&gt;width&lt;/code&gt; est proche de celui de &lt;code&gt;min-width&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Safari&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/safari.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Opera&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/opera.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Chrome&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/chrome.png&quot; /&gt; supporté&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;depassement&quot;&gt;18.2# Dépassement&lt;/h3&gt;
&lt;p&gt;Dans certains cas, le contenu d&amp;#8217;un bloc déborde car la taille définie est trop courte. Il existe plusieurs manières de gérer ce problème offertes grâce à la propriété &lt;code&gt;overflow&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;La valeur &lt;code&gt;hidden&lt;/code&gt; permet de masquer le contenu débordant du bloc, &lt;code&gt;visible&lt;/code&gt; laissera le contenu déborder, &lt;code&gt;scroll&lt;/code&gt; affichera des scrollbars pour permettre à l&amp;#8217;utilisateur de voir la totalité du contenu du bloc sans déborder, enfin &lt;code&gt;auto&lt;/code&gt; permet de laisser le navigateur gérer le dépassement (généralement il affichera des scrollbars uniquement si le contenu déborde).&lt;/p&gt;
&lt;div class=&quot;tuto-css-text-align&quot; style=&quot;float: left;&quot;&gt;
&lt;ul&gt;&lt;li style=&quot;overflow: hidden; height: 50px;&quot;&gt;&lt;code&gt;hidden&lt;/code&gt;&lt;br /&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada, purus eget egestas suscipit, neque velit euismod odio, et lacinia urna urna varius eros.&lt;/li&gt;
&lt;li style=&quot;overflow: visible; height: 50px;&quot;&gt;&lt;code&gt;visible&lt;/code&gt;&lt;br /&gt;gravida ut aliquet non, tempor a arcu. Fusce consectetur, turpis a
viverra feugiat,&lt;/li&gt;
&lt;li style=&quot;overflow: scroll; height: 50px;&quot;&gt;&lt;code&gt;scroll&lt;/code&gt;&lt;br /&gt;
gravida ut aliquet non, tempor a arcu. Fusce consectetur, turpis a
viverra feugiat, lacus quam tincidunt nibh, nec pulvinar tortor dolor
eget metus. Etiam rhoncus consequat est, et lobortis urna porta id.
Praesent lacus sem, eleifend eu congue nec, euismod vel arcu.&lt;/li&gt;
&lt;li style=&quot;overflow: auto; height: 50px;&quot;&gt;&lt;code&gt;auto&lt;/code&gt;&lt;br /&gt;
gravida ut aliquet non, tempor a arcu. Fusce consectetur, turpis a
viverra feugiat, lacus quam tincidunt nibh, nec pulvinar tortor dolor
eget metus. Etiam rhoncus consequat est, et lobortis urna porta id.
Praesent lacus sem, eleifend eu congue nec, euismod vel arcu.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;spacer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&quot;bordures&quot;&gt;18.3# Bordures&lt;/h3&gt;
&lt;p&gt;Il existe trois notions définissant l&amp;#8217;apparence des bordures d&amp;#8217;un bloc&amp;#160;: l&amp;#8217;épaisseur, l&amp;#8217;aspect et la couleur. CSS offre un grand nombre de propriétés qui permettent de spécifier ces notions individuellement pour chacune des quatre bordures du bloc, ou de les définir globalement. Ainsi, la propriété &lt;code&gt;border&lt;/code&gt; concerne toutes les bordures, tandis que &lt;code&gt;border-top&lt;/code&gt;, &lt;code&gt;border-bottom&lt;/code&gt;, &lt;code&gt;border-left&lt;/code&gt; et &lt;code&gt;border-right&lt;/code&gt;, correspondent respectivement à la bordure supérieure, inférieure, de gauche et de droite.&lt;/p&gt;
&lt;p&gt;Pour traiter l&amp;#8217;apparence des bordures, vous pouvez également utiliser &lt;code&gt;border-width&lt;/code&gt; (épaisseur), &lt;code&gt;border-color&lt;/code&gt; (couleur) et &lt;code&gt;border-style&lt;/code&gt; (aspect).&lt;/p&gt;
&lt;p&gt;Il est enfin possible d&amp;#8217;utiliser ces propriétés pour chacune des bordures, par exemple, pour définir la couleur de la bordure supérieure, vous pourrez utiliser &lt;code&gt;border-top-color&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Avant de s&amp;#8217;intéresser à quelques exemples qui devraient éclaircir tout ça, nous allons nous intéresser aux valeurs que peuvent porter ces propriétés&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;L&amp;#8217;épaisseur de la bordure est généralement définie par une valeur en pixels (en millimètres pour l&amp;#8217;impression), ou avec les valeurs &lt;code&gt;thin&lt;/code&gt; (fin), &lt;code&gt;medium&lt;/code&gt; (moyen), &lt;code&gt;thick&lt;/code&gt; (épais). Ces trois dernières valeurs sont rarement utilisées car elles dépendent de généralement du navigateur, l&amp;#8217;intégrateur n&amp;#8217;a donc pas toujours le contrôle sur l&amp;#8217;aspect.&lt;/li&gt;
&lt;li&gt;La couleur est définie de la même manière que &lt;a href=&quot;http://www.martiusweb.net/post/La-mise-en-forme-du-texte#chap-les-couleurs-du-texte&quot;&gt;la couleur du texte&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Enfin, l&amp;#8217;aspect admet plusieurs valeurs correspondant au style du trait&amp;#160;:
&lt;ul&gt;&lt;li&gt;&lt;code&gt;none&lt;/code&gt;, &lt;code&gt;hidden&lt;/code&gt;&amp;#160;: ces deux valeurs signifient que la bordure est absente (son épaisseur est égale à 0),&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dotted&lt;/code&gt;&amp;#160;: le trait est en pointillés,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dashed&lt;/code&gt;&amp;#160;: le trait est dessiné par des tirets,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;solid&lt;/code&gt;&amp;#160;: le trait est continu,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;double&lt;/code&gt;&amp;#160;: la bordure est constituée de deux traits, la largeur de la bordure correspond à la largeur des deux traits et de l&amp;#8217;espace entre les deux,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;groove&lt;/code&gt;&amp;#160;: la bordure forme un cadre dont le contenu semble placé &lt;em&gt;devant&lt;/em&gt; la bordure,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ridge&lt;/code&gt;&amp;#160;: la bordure forme un cadre dont le contenu semble placé &lt;em&gt;derrière&lt;/em&gt; la bordure,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;inset&lt;/code&gt;&amp;#160;: le bloc forme un creux,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;outset&lt;/code&gt;&amp;#160;: le bloc est surélevé.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img title=&quot;Aperçu des styles de bordures, juin 2009&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/p16ex01.png&quot; /&gt;&lt;/p&gt;
&lt;ul class=&quot;tuto-css-browsers-short&quot;&gt;&lt;li&gt;&lt;img alt=&quot;Icone Mozilla Firefox&quot; src=&quot;http://www.martiusweb.net/post/../themes/martiusweb/images/icons/browsers16/ff.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Microsoft Internet Explorer&quot; src=&quot;http://www.martiusweb.net/post/../themes/martiusweb/images/icons/browsers16/ie.png&quot; /&gt; &lt;code&gt;hidden&lt;/code&gt; n&amp;#8217;est pas interprété avant la version 8.&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Safari&quot; src=&quot;http://www.martiusweb.net/post/../themes/martiusweb/images/icons/browsers16/safari.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Opera&quot; src=&quot;http://www.martiusweb.net/post/../themes/martiusweb/images/icons/browsers16/opera.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Chrome&quot; src=&quot;http://www.martiusweb.net/post/../themes/martiusweb/images/icons/browsers16/chrome.png&quot; /&gt; supporté&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La valeur par défaut pour le style d&amp;#8217;une bordure est &lt;code&gt;none&lt;/code&gt;, il est donc nécessaire de choisir explicitement l&amp;#8217;aspect d&amp;#8217;une bordure pour l&amp;#8217;afficher. Si aucune couleur n&amp;#8217;est définie, c&amp;#8217;est celle du texte qui est utilisée, tandis que l&amp;#8217;épaisseur par défaut est &lt;code&gt;medium&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Ainsi, la manière la plus directe de définir une bordure est d&amp;#8217;utiliser la propriété &lt;code&gt;border&lt;/code&gt; en définissant l&amp;#8217;épaisseur, l&amp;#8217;aspect et la couleur (l&amp;#8217;ordre n&amp;#8217;a pas d&amp;#8217;importance)&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;div &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;red&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;solid&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;pre&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-left-width&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;5px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-left-color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;aqua&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-left-style&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;dashed&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;Par ailleurs, il est possible de définir des valeurs distinctes pour chacune des bordures en utilisant &lt;code&gt;border&lt;/code&gt;. Quand deux valeurs sont indiquées, celles-ci correspondent respectivement aux bordures horizontales et aux bordures verticales. Si quatre valeurs sont définies, alors elles correspondent dans l&amp;#8217;ordre à la bordure supérieure, de droite, inférieure et de gauche (dans le sens des aiguilles d&amp;#8217;une montre).&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* équivaut à : */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-top&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-bottom&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-left&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;2px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;3px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;4px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* équivaut à : */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-top&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;1px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;2px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-bottom&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;3px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;border-left&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;4px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;h3 id=&quot;marges&quot;&gt;18.4# Marges&lt;/h3&gt;
&lt;p&gt;Un bloc possède une marge intérieure entre le contenu et la bordure et une marge à l&amp;#8217;extérieur.&lt;/p&gt;
&lt;p&gt;&lt;img title=&quot;Les marges intérieures et extérieures, juin 2009&quot; style=&quot;margin: 0 auto; display: block;&quot; alt=&quot;&quot; src=&quot;http://www.martiusweb.net/public/cours-xhtml/p16ex02.png&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Sur cette illustration, la zone bleue correspond à la marge extérieure (&lt;code&gt;margin&lt;/code&gt;), le trait noir à la bordure et la zone rouge à la marge intérieure (&lt;code&gt;padding&lt;/code&gt;). Le rectangle central est la zone du contenu du bloc.&lt;/p&gt;
&lt;p&gt;Tout comme les bordures, il est possible de préciser des valeurs distinctes pour chacune des marges, grâce aux suffixes &lt;code&gt;-left&lt;/code&gt;, &lt;code&gt;-right&lt;/code&gt;, &lt;code&gt;-top&lt;/code&gt; et &lt;code&gt;-bottom&lt;/code&gt;, ou encore en définissant plusieurs valeurs pour les propriétés &lt;code&gt;margin&lt;/code&gt; et &lt;code&gt;padding&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;p &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;10px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;padding&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;5px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;blockquote &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;10px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;5px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;padding&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;0px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;10px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;pre &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;margin-left&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;15px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;ul class=&quot;tuto-css-browsers-short&quot;&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Mozilla Firefox&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/ff.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Microsoft Internet Explorer&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/ie.png&quot; /&gt; le support de &lt;code&gt;margin&lt;/code&gt; et &lt;code&gt;padding&lt;/code&gt; sous internet explorer peut poser des problèmes qui seront discutés au &lt;a href=&quot;http://www.martiusweb.net/post/Modele-des-blocs-W3C-et-Quirks-mode&quot;&gt;prochain chapitre sur le mode Quriks&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Safari&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/safari.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Opera&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/opera.png&quot; /&gt; supporté&lt;/li&gt;
&lt;li&gt;&lt;img alt=&quot;Icone Chrome&quot; src=&quot;http://www.martiusweb.net/post/./themes/martiusweb/images/icons/browsers16/chrome.png&quot; /&gt; supporté&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La propriété &lt;code&gt;margin&lt;/code&gt; supporte également la propriété &lt;code&gt;auto&lt;/code&gt; qui permet de centrer un bloc horizontalement, nous en discuterons au chapitre sur &lt;a href=&quot;http://www.martiusweb.net/post/Positionner-et-centrer-le-bloc&quot;&gt;le positionnement des blocs&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;fond&quot;&gt;18.5# Fond&lt;/h3&gt;
&lt;p&gt;Le fond d&amp;#8217;un bloc peut être une image ou une couleur unie. Dans ce dernier cas, vous pouvez utiliser indifféremment la propriété &lt;code&gt;background-color&lt;/code&gt; ou le raccourci &lt;code&gt;background&lt;/code&gt;, la valeur étant une couleur définie de la même manière que celle du texte ou des bordures.&lt;/p&gt;
&lt;p&gt;Le fond s&amp;#8217;applique sur l&amp;#8217;intérieur du bloc, les bordures et marges extérieures ne sont donc pas concernées. Par ailleurs, la valeur par défaut du fond étant &lt;code&gt;transparent&lt;/code&gt;, des blocs imbriqués seront affichés au dessus du fond du bloc parent.&lt;/p&gt;
&lt;p&gt;On complique un peu les choses&amp;#160;: pour insérer une image, utilisez la propriété &lt;code&gt;background-image&lt;/code&gt;, avec pour valeur &lt;code&gt;url('[adresse]')&lt;/code&gt;. L&amp;#8217;adresse de l&amp;#8217;image est relative à la feuille de style et non pas à la page&amp;#160;:&lt;/p&gt;
&lt;pre&gt;Exemple d'arborescence de fichiers :&lt;br /&gt;/&lt;br /&gt;| /images&lt;br /&gt;|  | background.png&lt;br /&gt;| /styles&lt;br /&gt;|  | styles.css&lt;br /&gt;| page.html&lt;/pre&gt;&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'../images/background.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;L&amp;#8217;image est alors placée en haut à gauche du bloc, si le bloc est plus grand que l&amp;#8217;image, celle-ci est répétée en mosaïque. Certaines propriétés CSS permettent de modifier ce comportement. La position peut être réglée verticalement ou horizontalement grâce à &lt;code&gt;background-position&lt;/code&gt;, la répétition avec &lt;code&gt;background-repeat&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;La position peut être indiquée en pixels ou en pourcentage (calculé selon la largeur ou la hauteur du bloc), ou à l&amp;#8217;aide de mots clés&amp;#160;:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;top&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt; ou &lt;code&gt;bottom&lt;/code&gt; en hauteur,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;left&lt;/code&gt;, &lt;code&gt;center&lt;/code&gt; ou &lt;code&gt;right&lt;/code&gt; en largeur.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Vous devrez préciser la valeur verticale (en hauteur) en premier puis la position horizontale. Si une seule valeur est précisée, la position horizontale sera 50% (&lt;code&gt;center&lt;/code&gt;). Il est possible de mélanger position en pixels et pourcentages. Les valeurs négatives sont autorisées.&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'monimage.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-position&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;30px&lt;/span&gt; &lt;span style=&quot;color: #933;&quot;&gt;10px&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;&lt;p&gt;La propriété &lt;code&gt;background-repeat&lt;/code&gt; admet quatre valeurs&amp;#160;: &lt;code&gt;repeat&lt;/code&gt; (par défaut), &lt;code&gt;no-repeat&lt;/code&gt; (aucune répétition), &lt;code&gt;repeat-x&lt;/code&gt; (répéter à l&amp;#8217;horizontal) et &lt;code&gt;repeat-y&lt;/code&gt; (répéter verticalement).&lt;/p&gt;
&lt;p&gt;Enfin, la propriété &lt;code&gt;background-attachment&lt;/code&gt; permet de spécifier où sera &lt;em&gt;collé le papier peint&lt;/em&gt;&amp;#160;: sur le fond du bloc ou sur le fond de la page. En fait, cela permet de choisir le comportement du fond en fonction du déroulement de la page à l&amp;#8217;aide des ascenseurs. La valeur par défaut &lt;code&gt;scroll&lt;/code&gt; signifie que le fond suivra le mouvement du bloc, tandis que la valeur &lt;code&gt;fixed&lt;/code&gt; signifie que le fond sera collé au fond de la page et ne bougera pas à l&amp;#8217;écran, seul le contenu sera déplacé.&lt;/p&gt;
&lt;p&gt;Vous pouvez voir cette propriété à l&amp;#8217;œuvre sur &lt;a hreflang=&quot;fr&quot; href=&quot;http://www.martiusweb.net/post/public/cours-xhtml/exemple-18.html&quot; onclick=&quot;window.open(this.href); return false;&quot;&gt;la page de test&lt;/a&gt;. Pour vérifier son fonctionnement, vous devez vous assurer que la hauteur de la fenêtre de votre navigateur soit inférieure à la hauteur de la page, pour pouvoir utiliser les ascenseurs.&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'monimage.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background-attachment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;fixed&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/pre&gt;
&lt;p&gt;Vous pouvez maintenant regrouper ces valeurs grâce à la propriété raccourci &lt;code&gt;background&lt;/code&gt; qui peut s&amp;#8217;écrire ainsi&amp;#160;:&lt;/p&gt;
&lt;pre class=&quot;css sourcecode css&quot; style=&quot;font-family:monospace;&quot;&gt;&lt;ol&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;couleur&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;image&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;répétition&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;attachement&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;position&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* Toutes les propriétés résumées en une seule */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;red&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'./images/bg.png'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;no-repeat&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;top&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;center&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/* ...ou seulement celles qui sont nécessaires */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;font-weight: normal; vertical-align:top;&quot;&gt;&lt;div style=&quot;font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;background&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;color: #993333;&quot;&gt;url&lt;/span&gt;&lt;span style=&