<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emanuele Feronato &#187; Tutorials</title>
	<atom:link href="http://www.emanueleferonato.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Thu, 02 Sep 2010 09:32:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Creation of a Flash coloring book</title>
		<link>http://www.emanueleferonato.com/2010/03/18/creation-of-a-flash-coloring-book/</link>
		<comments>http://www.emanueleferonato.com/2010/03/18/creation-of-a-flash-coloring-book/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 15:34:59 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Game design]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2546</guid>
		<description><![CDATA[Before you start reading this tutorial, there is something you must do. Turn off the lights, close your eyes, raise your hands, and say: &#171; Hail, Lord of Flash Game. Shall I read this tutorial and forget it before I try to flood the web with another silly Coloring Book Game &#187; Really, seriously&#8230; I [...]]]></description>
			<content:encoded><![CDATA[<p>Before you start reading this tutorial, there is something you must do.</p>
<p>Turn off the lights, close your eyes, raise your hands, and say:</p>
<p>&laquo; Hail, Lord of Flash Game. Shall I read this tutorial and forget it before I try to flood the web with another silly Coloring Book Game &raquo;</p>
<p>Really, seriously&#8230; I am showing you how do it but please, please&#8230; don&#8217;t do it.</p>
<p><strong>Finding the right image</strong></p>
<p>If you can&#8217;t draw your image, you&#8217;ll have to download it from the web. Try to Google for <a href="http://www.google.com/search?client=firefox-a&#038;rls=org.mozilla%3Aen-US%3Aofficial&#038;channel=s&#038;hl=en&#038;source=hp&#038;q=coloring+book&#038;btnG=Google+Search" target = "_blank">coloring book</a> and you&#8217;ll know what I mean.</p>
<p>Just remember the &#8220;copyright&#8221; word&#8230; I don&#8217;t think you&#8217;re allowed to use Ben 10 or Hello Kitty images&#8230; but if you are about to create a Flash coloring book, you are an evil person and stealing artworks won&#8217;t be a problem.</p>
<p>The image I&#8217;ll use is taken from <a href="http://www.coloring-book.info/" target = "_blank">www.coloringbook.info</a></p>
<p><strong>Main concept</strong></p>
<p>Every colorable part is a distinct movieclip, and its color is dynamically changed with Actionscript</p>
<p><strong>Converting the image</strong></p>
<p>First, you need to import it into Flash </p>
<p><code>File->Import->Import to Stage</code></p>
<p><img src="/wp-content/uploads/2010/03/coloring01.png" /></p>
<p>Then, select the image on the stage, and convert it from bitmap to vector<span id="more-2546"></span></p>
<p><code>Modify->Bitmap->Trace Bitmap</code></p>
<p>with these settings:</p>
<p>Color threshold: 100</p>
<p>Minimum area: 1</p>
<p>Curve fit: Very Smooth</p>
<p>Corner threshold: Few Corners</p>
<p><img src="/wp-content/uploads/2010/03/coloring02.png" /></p>
<p>Now you have your bitmap converted into a Flash shape. Select all the black outline clicking on every black line you see while pressing Shift, then convert it to a symbol</p>
<p><code>Modify->Convert to Symbol</code></p>
<p>name it <code>outline</code> and don&#8217;t check <code>Export for Actionscript</code> </p>
<p><img src="/wp-content/uploads/2010/03/coloring09.png" /></p>
<p>Now do the same thing with the head&#8230;</p>
<p><img src="/wp-content/uploads/2010/03/coloring10.png" /></p>
<p>Then with the remaining body parts and eventually the background. Once the shape has been divided into objects, select all objects on the stage and convert them as a unique symbol you will call <code>teddy_mc</code>.</p>
<p>This time remember to check <code>Export for Actionscript</code></p>
<p><img src="/wp-content/uploads/2010/03/coloring06.png" /></p>
<p>Now you can delete everything from the stage and remove the image from the library.</p>
<p>Now your library should look like this one:</p>
<p><img src="/wp-content/uploads/2010/03/coloring071.png" /></p>
<p>Now edit <code>teddy_mc</code> movieclip, selecting every movieclip inside it (head, outline, &#8230;) and giving it a proper instance name&#8230; <code>head</code> for the head, <code>feet</code> for the feet and so on</p>
<p><img src="/wp-content/uploads/2010/03/coloring11.png" /></p>
<p>Obviously tracing a bitmap won&#8217;t give the same quality results as if you were able to draw your coloring book by yourself</p>
<p>Finally you are ready to code some interesting lines</p>
<p><strong>Actionscript</strong></p>
<p>The aim of this script is putting on stage the teddy bear, a three color palette, setting a default color, allowing people to change color clicking on the palette, and painting the teddy bear.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span>.<span style="color: #004993;">ColorTransform</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span>.<span style="color: #004993;">MouseEvent</span>;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> coloring extends <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> teddy<span style="color: #000000; font-weight: bold;">:</span>teddy_mc = <span style="color: #0033ff; font-weight: bold;">new</span> teddy_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> palette<span style="color: #000000; font-weight: bold;">:</span>palette_mc;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> pal_color<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">ColorTransform</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">colors</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span>=<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span>0xFF0000,0x00FF00,0x0000FF<span style="color: #000000;">&#41;</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> current_color<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> coloring<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>teddy<span style="color: #000000;">&#41;</span>;
			teddy.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,on_teddy_click<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>=<span style="color: #000000; font-weight:bold;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000; font-weight:bold;">3</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				palette = <span style="color: #0033ff; font-weight: bold;">new</span> palette_mc<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				pal_color=palette.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span>;
				pal_color.<span style="color: #004993;">color</span>=<span style="color: #004993;">colors</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>;
				palette.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span>=pal_color;
				palette.<span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000; font-weight: bold;">+</span>i<span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000; font-weight:bold;">60</span>;
				palette.<span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">300</span>;
				palette.ind=i;
				<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>palette<span style="color: #000000;">&#41;</span>;
				palette.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span>.<span style="color: #004993;">CLICK</span>,on_palette_click<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> on_palette_click<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> palette_clicked<span style="color: #000000; font-weight: bold;">:</span>palette_mc=e.<span style="color: #004993;">currentTarget</span> <span style="color: #0033ff; font-weight: bold;">as</span> palette_mc;
			current_color=palette_clicked.ind;
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> on_teddy_click<span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span>; i <span style="color: #000000; font-weight: bold;">&lt;</span> teddy.<span style="color: #004993;">numChildren</span>; i<span style="color: #000000; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>teddy.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>.<span style="color: #004993;">hitTestPoint</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span>,<span style="color: #004993;">mouseY</span>,<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
					pal_color=teddy.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span>;
					pal_color.<span style="color: #004993;">color</span>=<span style="color: #004993;">colors</span><span style="color: #000000;">&#91;</span>current_color<span style="color: #000000;">&#93;</span>;
					teddy.<span style="color: #004993;">getChildAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>.<span style="color: #004993;">transform</span>.<span style="color: #004993;">colorTransform</span>=pal_color;
				<span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Line 3</strong>: <code>ColorTransform</code> class lets you adjust the color values in a display object</p>
<p><strong>Line 6</strong>: Declaring the teddy bear object</p>
<p><strong>Line 7</strong>: Declaring the palette: it&#8217;s a simple white circle that will be instanced three times in three different colors</p>
<p><strong>Line 8</strong>: Variable used to handle color adjustment</p>
<p><strong>Line 9</strong>: Array with possible colors&#8230; in this case red, green and blue</p>
<p><strong>Line 10</strong>: Setting the default color</p>
<p><strong>Line 12</strong>: Placing the teddy bear on stage</p>
<p><strong>Line 13</strong>: Adding a listener to know when I&#8217;m clicking on it</p>
<p><strong>Line 14</strong>: Beginning of the loop that will create the three-color palette</p>
<p><strong>Line 15</strong>: Creating a new palette object</p>
<p><strong>Lines 16-18</strong>: Giving the palette object the <code>i</code>-th color in the <code>colors</code> array</p>
<p><strong>Lines 19-20</strong>: Setting the palette position on the stage</p>
<p><strong>Line 21</strong>: Giving the palette an index, to easily recognize it</p>
<p><strong>Line 22</strong>: Adding the palette on stage</p>
<p><strong>Line 23</strong>: Adding a listener to know when I&#8217;m clicking on a palette</p>
<p><strong>Lines 26-29</strong>: Changing the current color according to the index (see <strong>line 21</strong>) of the palette I clicked</p>
<p><strong>Line 31</strong>: Looping through all teddy&#8217;s children (the colorable parts)</p>
<p><strong>Line 32</strong>: Checking which movieclip I clicked</p>
<p><strong>Lines 33-35</strong> Changing its color in the same way shown at <strong>lines 16-18</strong></p>
<p>And this is the result:</p>
<p><embed src="/wp-content/uploads/2010/03/coloring.swf" allowscriptaccess="always" menu="false" quality="high" width="500" height="400" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></p>
<p>Play with colors&#8230; as you can see the antialiasing sucks&#8230; but you can make it perfect if you draw the image by yourself.</p>
<p><a href="/wp-content/uploads/2010/03/coloring.zip">Download the source code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/03/18/creation-of-a-flash-coloring-book/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Color difference algorithm &#8211; part 2</title>
		<link>http://www.emanueleferonato.com/2009/09/08/color-difference-algorithm-part-2/</link>
		<comments>http://www.emanueleferonato.com/2009/09/08/color-difference-algorithm-part-2/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 15:24:17 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1627</guid>
		<description><![CDATA[It&#8217;s time to see how to calculate difference between two colors. I am using the CIE1994 formula because it&#8217;s quite accurate and not that complex to calculate. Here it is, assuming I have two colors in Lab format where (thanx to Bruce Lindbloom) First, I am turning the scripts explained at Color difference algorithm into [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time to see how to calculate difference between two colors.</p>
<p>I am using the <strong>CIE1994</strong> formula because it&#8217;s quite accurate and not that complex to calculate.</p>
<p>Here it is, assuming I have two colors in Lab format</p>
<p><img src="/images/Eqn_DeltaE_CIE94_1.gif" alt="" /></p>
<p>where</p>
<p><img src="/images/Eqn_DeltaE_CIE94_2.gif" alt="" /></p>
<p>(thanx to <strong><a target = "_blank" href="http://www.brucelindbloom.com/index.html?ColorDifferenceCalc.html">Bruce Lindbloom</a></strong>)<span id="more-1627"></span></p>
<p>First, I am turning the scripts explained at <a href="http://www.emanueleferonato.com/2009/08/28/color-differences-algorithm/">Color difference algorithm</a> into functions, this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rgb_to_xyz<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rgb</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$red</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rgb</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$green</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rgb</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rgb</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
     <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$red</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$green</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$blue</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_green</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_blue</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000088;">$_red</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_green</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.4124</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.3576</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.1805</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.2126</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.7152</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.0722</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.0193</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.1192</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.9505</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$y</span><span style="color: #339933;">,</span><span style="color: #000088;">$z</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> xyz_to_lab<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xyz</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xyz</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xyz</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xyz</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #339933;">/</span><span style="color:#800080;">95.047</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$z</span><span style="color: #339933;">/</span><span style="color:#800080;">108.883</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_z</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_z</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_z</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000088;">$l</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">116</span><span style="color: #339933;">*</span><span style="color: #000088;">$_y</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$a</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">-</span><span style="color: #000088;">$_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$b</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">-</span><span style="color: #000088;">$_z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$l</span><span style="color: #339933;">,</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now, it&#8217;s time to determine color difference, using the above formula:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> de_1994<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lab1</span><span style="color: #339933;">,</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$c1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$c2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$dc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c1</span><span style="color: #339933;">-</span><span style="color: #000088;">$c2</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$dl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$da</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$lab1</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #000088;">$lab2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$dh</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$da</span><span style="color: #339933;">*</span><span style="color: #000088;">$da</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">*</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dc</span><span style="color: #339933;">*</span><span style="color: #000088;">$dc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$first</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dl</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$second</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dc</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color:#800080;">0.045</span><span style="color: #339933;">*</span><span style="color: #000088;">$c1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$third</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dh</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">+</span><span style="color:#800080;">0.015</span><span style="color: #339933;">*</span><span style="color: #000088;">$c1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first</span><span style="color: #339933;">*</span><span style="color: #000088;">$first</span><span style="color: #339933;">+</span><span style="color: #000088;">$second</span><span style="color: #339933;">*</span><span style="color: #000088;">$second</span><span style="color: #339933;">+</span><span style="color: #000088;">$third</span><span style="color: #339933;">*</span><span style="color: #000088;">$third</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And you&#8217;ll find the difference between colors.</p>
<p>Next time, a real application using all this boring theory&#8230; (you will be surprised&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/09/08/color-difference-algorithm-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Video tutorial: 5 detailed Adobe Photoshop killer tips</title>
		<link>http://www.emanueleferonato.com/2009/08/31/video-tutorial-5-detailed-adobe-photoshop-killer-tips/</link>
		<comments>http://www.emanueleferonato.com/2009/08/31/video-tutorial-5-detailed-adobe-photoshop-killer-tips/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:09:56 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1597</guid>
		<description><![CDATA[Did you ever want to master Adobe Photoshop? In this video I unveil 5 killer tips I use almost every day. Follow some simple steps and you will be able to: 1) Remove objects from a photo 2) Correct red eyes 3) Make a photo look older 4) Create realistic fog 5) Turn a night [...]]]></description>
			<content:encoded><![CDATA[<p>Did you ever want to master Adobe Photoshop?</p>
<p>In this video I unveil 5 killer tips I use almost every day.</p>
<p>Follow some simple steps and you will be able to:</p>
<p>1) Remove objects from a photo</p>
<p>2) Correct red eyes</p>
<p>3) Make a photo look older</p>
<p>4) Create realistic fog</p>
<p>5) Turn a night scene into a day one</p>
<p>All in a single video, quick and easy to understand<span id="more-1597"></span></p>
<p><object width="520" height="417"><param name="movie" value="http://www.youtube.com/v/4KAiF9mJqHU&#038;hl=it&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/4KAiF9mJqHU&#038;hl=it&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="520" height="417"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/08/31/video-tutorial-5-detailed-adobe-photoshop-killer-tips/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Color difference algorithm</title>
		<link>http://www.emanueleferonato.com/2009/08/28/color-differences-algorithm/</link>
		<comments>http://www.emanueleferonato.com/2009/08/28/color-differences-algorithm/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 19:53:46 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1582</guid>
		<description><![CDATA[I will probably write some posts and tutorials about this topic, becaue color differences are very useful when designing a color scheme or some elements to be placed on a given background color. And for a wide range of applications working with color spaces. Anyway, at the moment just know Wikipedia says there is a [...]]]></description>
			<content:encoded><![CDATA[<p>I will probably write some posts and tutorials about this topic, becaue color differences are very useful when designing a color scheme or some elements to be placed on a given background color.</p>
<p>And for a wide range of applications working with color spaces.</p>
<p><img src="/images/colorspace.jpg" alt="" /></p>
<p>Anyway, at the moment just know <a target = "_blank" href="http://en.wikipedia.org/wiki/Color_difference">Wikipedia</a> says there is a <strong>International Commission on Illumination (CIE)</strong> who calls distance between colors <code>dE</code>.</p>
<p>Obviously the meaning is removing subjectivity&#8230; I can see two colors &#8220;almost identical&#8221; while you can see the same ones &#8220;slighty different&#8221;.</p>
<p>In theory, a <code>dE</code> of under 1.0 is supposed to be indistinguishable unless the samples are adjacent to one another</p>
<p>To make things a little bit harder, there are different ways to calculate color difference&#8230; three formulas the CIE refined during the years&#8230; <strong>CIE76</strong>, <strong>CIE94</strong> and <strong>CIEDE2000</strong>.<span id="more-1582"></span></p>
<p>If you want to study in depth color difference, or even small color differences may be critical for your work, then the <a target = "_blank" href="http://www.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf">CIEDE2000</a> is the most advanced way to determine color difference, and the one with the most complex formula.</p>
<p>Complex formulas aren&#8217;t what I am looking for because I have in mind something a little bit complicated than just measuring color difference, and the CIE76 is maybe too basic, so at the moment I am testing the CIE94 formula.</p>
<p>Before examining the formula, let me introduce you some ways to define colors.</p>
<p>If you are used to web design, you&#8217;ll probably know the <strong>RGB</strong> color model. The name of the model comes from the initials of the three additive primary colors, Red, Green, and Blue, that are added to reproduce all colors.</p>
<p>But RGB is not the only way you can code colors.<!--more--></p>
<p><strong>Color models</strong></p>
<p>Here it is a brief list of color models&#8230; some of them are useful, some others not that useful, anyway let&#8217;s see them&#8230;</p>
<p><strong>RGB</strong>: The most famous color encoding, as explained before</p>
<p><strong>CMY</strong>: The complement of <code>RGB</code>, named after Cyan, Magenta and Yellow.</p>
<p><strong>CMYK</strong>: Same as <code>CMY</code> with the added <code>K</code> parameter which is blacK.  It is the system used by printers.</p>
<p><strong>HSV</strong> or <strong>HSB</strong>: A system which represents color as Hue, Saturation and Value. <code>Hue</code> is what is seen as the color.  <code>Saturation</code> is how &#8220;pure&#8221; is the color.  0% is grey and 100% is a pure color. <code>Value</code> represents the Brightness.  </p>
<p><strong>HSL</strong>: Just like <code>HSV</code> but instead of Value we have lightness.  This time, maximum saturation is at the mid-point (50%).  0% is black and 100% is white.</p>
<p><strong>XYZ</strong>: This is also called &#8220;norm color system&#8221; and it&#8217;s a superset of <code>RGB</code>. It uses <strong>tristimulus values</strong> when encoding. <code>X</code>, <code>Y</code> and <code>Z</code> are all calculated through color-matching functions and are always positive.</p>
<p>The human eye has receptors (called cone cells) for short (S), middle (M), and long (L) wavelengths. Thus in principle, three parameters describe a color sensation. The tristimulus values of a color are the amounts of three primary colors in a three-component additive color model needed to match that test color.</p>
<p><strong>Yxy</strong>: Known as the Trichromatic coordinates. <code>Y</code> represents the brightness and <code>(x,y)</code> hue and saturation.</p>
<p><strong>CIE Lab</strong>: This color scale is based on the opponent color theory. <code>L</code> represents light-dark, <code>a</code> represents red-green and <code>b</code> represents yellow-blue.</p>
<p>There are some more systems, anyway, at the moment we are interested in <strong>Lab</strong> color space that unlike the <code>RGB</code> and <code>CMYK</code> color models, is designed to approximate human vision.</p>
<p>Since we are used to <code>RGB</code> (and eventually to <code>CYMK</code> if you work in print), we need to convert these formats into <code>Lab</code> color space, and in order to do it we must first convert them in <code>XYZ</code> color space, and then convert them again to <code>Lab</code> values.</p>
<p><strong>RGB -> XYZ conversion</strong></p>
<p>On the <a target = "_blank" href="http://www.w3.org/Graphics/Color/sRGB">Standard Default Color Space for the Internet</a> page on the &#8220;Colorimetric definitions and digital encodings&#8221; chapter you will find the matrix used for color conversion and the previous adjustments to do.</p>
<p>So, having a <code>RGB</code> value with red, green and blue values as base 10 integers from 0 to 255, you can convert <code>RGB</code> to <code>XYZ</code> this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// RGB values</span>
<span style="color: #000088;">$red</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">39</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$green</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">176</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$blue</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">165</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// same values, from 0 to 1</span>
<span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$red</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$green</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$blue</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// adjusting values</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_red</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_red</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_green</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_green</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_green</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.04045</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">+</span><span style="color:#800080;">0.055</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color:#800080;">1.055</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_blue</span><span style="color: #339933;">,</span><span style="color:#800080;">2.4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_blue</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_blue</span><span style="color: #339933;">/</span><span style="color:#800080;">12.92</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$_red</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_green</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_blue</span> <span style="color: #339933;">*=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// applying the matrix</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.4124</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.3576</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.1805</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.2126</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.7152</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.0722</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$z</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_red</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.0193</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_green</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.1192</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$_blue</span> <span style="color: #339933;">*</span> <span style="color:#800080;">0.9505</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// displaying the values</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$x</span> <span style="color: #006699; font-weight: bold;">$y</span> <span style="color: #006699; font-weight: bold;">$z</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now, next step:</p>
<p><strong>XYZ -> Lab conversion</strong></p>
<p>In order to convert <code>XYZ</code> to <code>Lab</code>, first we must set the <strong>white point</strong>, that is a set of tristimulus values or chromaticity coordinates that serve to define the color &#8220;white&#8221; in image capture, encoding, or reproduction.</p>
<p>Then, following the formula found on <a target = "_blank" href="http://en.wikipedia.org/wiki/Lab_color_space#CIE_XYZ_to_CIE_L.2Aa.2Ab.2A_.28CIELAB.29_and_CIELAB_to_CIE_XYZ_conversions">this page</a>, we can solve the problem this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$x</span><span style="color: #339933;">/</span><span style="color:#800080;">95.047</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$y</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$z</span><span style="color: #339933;">/</span><span style="color:#800080;">108.883</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// adjusting the values</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_x</span> <span style="color: #339933;">=</span> <span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_x</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_y</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_z</span><span style="color: #339933;">&gt;</span><span style="color:#800080;">0.008856</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_z</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$_z</span> <span style="color: #339933;">=</span> <span style="color:#800080;">7.787</span><span style="color: #339933;">*</span><span style="color: #000088;">$_z</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">16</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">116</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$l</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">116</span><span style="color: #339933;">*</span><span style="color: #000088;">$_y</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_x</span><span style="color: #339933;">-</span><span style="color: #000088;">$_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span><span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_y</span><span style="color: #339933;">-</span><span style="color: #000088;">$_z</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// displaying the values</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$l</span> <span style="color: #006699; font-weight: bold;">$a</span> <span style="color: #006699; font-weight: bold;">$b</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>And in the end, the orginal <code>RGB 39,176,165</code> is converted in <code>Lab 65.12, -37.39, -4.54</code> that is very close to Photoshop CS4 <code>Lab 65,-38,-5</code> that probably uses a different white point.</p>
<p>Next time we&#8217;ll see something interesting to do with these formulas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/08/28/color-differences-algorithm/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Understanding MochiAds Publisher Bridge – Part 3</title>
		<link>http://www.emanueleferonato.com/2009/08/24/understanding-mochiads-publisher-bridge-%e2%80%93-part-3/</link>
		<comments>http://www.emanueleferonato.com/2009/08/24/understanding-mochiads-publisher-bridge-%e2%80%93-part-3/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 14:20:23 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1562</guid>
		<description><![CDATA[In part 1 we saw how to configure a cross-domain policy file, calling the javascript and send the results to a webpage. In part 2 we saw how to prevent cheating. In this 3rd part we&#8217;ll make something useful with it. I am going to add to my Triqui MochiAds Arcade theme for WordPress a [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.emanueleferonato.com/2009/07/16/understanding-mochiads-publisher-bridge/">part 1</a> we saw how to configure a cross-domain policy file, calling the javascript and send the results to a webpage.</p>
<p>In <a href="http://www.emanueleferonato.com/2009/08/17/understanding-mochiads-publisher-bridge-part-2/">part 2</a> we saw how to prevent cheating.</p>
<p>In this 3rd part we&#8217;ll make something useful with it. I am going to add to my <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">Triqui MochiAds Arcade theme for WordPress</a> a WordPress widget showing the latest scores submitted from my portal, <a href="http://www.triqui.com/" target = "_blank">triqui.com</a>, but once you understand how to do it, you can easily change the script to make it fit your needs.</p>
<p>The first thing to do is creating a new table in your WordPress database. At this time, I only want to save player name, score and obviously the game unique id.</p>
<p>So my MySQL query is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> <span style="color: #ff0000;">`wp_mochi_scores`</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`when`</span> timestamp <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> CURRENT_TIMESTAMP<span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`gameid`</span> text COLLATE utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`name`</span> text COLLATE utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #ff0000;">`score`</span> text COLLATE utf8_unicode_ci <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM  <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>utf8 COLLATE<span style="color: #66cc66;">=</span>utf8_unicode_ci;</pre></td></tr></table></div>

<p>as you can see, I added a primary auto increment key and a timestamp field, to determine when the score has been saved.<span id="more-1562"></span></p>
<p>Then I need to change <code>postscores.php</code> this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// your secret key</span>
<span style="color: #000088;">$key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;f26ebddd6fcfb796ac1841bcc57af057&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// initializing an empty string - not strictly necessary</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ordering the associative POST array by keys</span>
<span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop scanning through all POST array</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$varname</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$varvalue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// if the key is not &quot;signature&quot; then append key and url encoded values to the string</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$varname</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;signature&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$string</span><span style="color: #339933;">.=</span><span style="color: #000088;">$varname</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$varvalue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// removing the last character (a &quot;&amp;&quot;&quot;)</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// appeding the secret key to the string</span>
<span style="color: #000088;">$string</span><span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// comparing the md5 encryption of the string with the &quot;signature&quot; variable</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>signature<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// requiring the relative path to your wp-config.php file</span>
     <span style="color: #666666; font-style: italic;">// according to your wp installation, this path may change</span>
     <span style="color: #666666; font-style: italic;">// but in most cases it will work this way</span>
     <span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;../../../wp-config.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// connecting to wp database</span>
     <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>DB_HOST<span style="color: #339933;">,</span> DB_USER<span style="color: #339933;">,</span> DB_PASSWORD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// selecting the proper database</span>
     <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #339933;">,</span>DB_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// inserting the game tag, the score and the player name</span>
     <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;insert into &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$table_prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;mochi_scores (gameid,name,score) values('<span style="color: #006699; font-weight: bold;">$_POST[gameID]</span>','<span style="color: #006699; font-weight: bold;">$_POST[name]</span>','<span style="color: #006699; font-weight: bold;">$_POST[score]</span>')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now I have a script that silently populates the <code>mochi_scores</code> table with the latest scores.</p>
<p>It&#8217;s time to show them in a widget.</p>
<p>If you don&#8217;t know what is a widget or how to create and activate it, follow <a href="http://www.emanueleferonato.com/2008/02/15/how-to-create-a-wordpress-widget/">How to create a WordPress Widget</a>.</p>
<p>I created a file called mochi_lastscores.php with this content:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Mochi lastscores
Plugin URI: http://www.emanueleferonato.com/
Description: Displays last scores submitted in your MochiAds Arcade
Author: Emanuele Feronato
Version: 1.0
Author URI: http://www.emanueleferonato.com/
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> mochi_lastscores_widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">echo</span><span style="color: #0000ff;">&quot;&lt;li&gt;&lt;h2&gt;LATEST SCORES&lt;/h2&gt;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// selecting the latest 10 scores</span>
     <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;mochi_scores order by id desc limit 0,10&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// saving scores inside an array called &quot;scores&quot;</span>
     <span style="color: #000088;">$scores</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scores</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">// scanning all scores</span>
          <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scores</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$score</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               <span style="color: #666666; font-style: italic;">// looking for the entry in my mochi game table with the same game tag as the one I saved</span>
               <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;mochi where game_tag = <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$score[gameid]</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #666666; font-style: italic;">// saving the entry in an array called &quot;game&quot;</span>
               <span style="color: #000088;">$game</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #666666; font-style: italic;">// if the entry has a blog_id...</span>
               <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$game</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>blog_id<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">// selecting the post in the wp post table with the same id as the game found in the mochi games table</span>
                    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prefix</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;posts where ID = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$game</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>blog_id<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// saving the entry in a variable called &quot;post&quot;</span>
                    <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span>ARRAY_A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">// printing the entry in the theme</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;span class = <span style="color: #000099; font-weight: bold;">\&quot;</span>turnwhite<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$score[name]</span>&lt;/span&gt; just scored &lt;span class = <span style="color: #000099; font-weight: bold;">\&quot;</span>turnwhite<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$score[score]</span>&lt;/span&gt; on &lt;a href = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>guid<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$game</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>name<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> init_mochi_lastscores<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     register_sidebar_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Mochi Last Scores&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mochi_lastscores_widget&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plugins_loaded&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;init_mochi_lastscores&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>And you can find the result in the left sidebar in my <a href="http://www.triqui.com/" target = "_blank">triqui.com</a> portal.</p>
<p>This feature will be added in my next <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">Triqui MochiAds Arcade theme for WordPress</a> update, but meanwhile you can easily set it up on your own.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/08/24/understanding-mochiads-publisher-bridge-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Understanding MochiAds Publisher Bridge &#8211; Part 2</title>
		<link>http://www.emanueleferonato.com/2009/08/17/understanding-mochiads-publisher-bridge-part-2/</link>
		<comments>http://www.emanueleferonato.com/2009/08/17/understanding-mochiads-publisher-bridge-part-2/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 21:04:16 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1541</guid>
		<description><![CDATA[This is the second part of Understanding MochiAds Publisher Bridge. In the first step I showed you how to configure a cross-domain policy file, calling the javascript and send the results to a webpage. Now it&#8217;s time to prevent cheating. As you can see, it&#8217;s very easy to send some POST variables to a webpage, [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of <a href="http://www.emanueleferonato.com/2009/07/16/understanding-mochiads-publisher-bridge/">Understanding MochiAds Publisher Bridge</a>.</p>
<p>In the first step I showed you how to configure a cross-domain policy file, calling the javascript and send the results to a webpage.</p>
<p>Now it&#8217;s time to prevent cheating.</p>
<p>As you can see, it&#8217;s very easy to send some POST variables to a webpage, and it&#8217;s even easier to do it when you know the name of such webpage&#8230; and in our case you can know it simply looking at the html.</p>
<p>If you look at the html of the page containing <a href="http://www.triqui.com/2009/06/19/mazeroll/" target = "_blank">Mazeroll</a>, it&#8217;s clear the name of the page I send the POST array to is <code>postscores.php</code>.</p>
<p>So we have to prevent cheating.</p>
<p>That&#8217;s why in your <a href="https://www.mochimedia.com/r/972ae333a3c92a2a" target = "_blank">MochiAds</a> publisher settings page you&#8217;ll find a secret key that can be used to authenticate the score data sent from the Bridge to your server.</p>
<p>In your POST variables you can find one called <code>signature</code>.<span id="more-1541"></span></p>
<p>This is an MD5 hash of the POST vars + your secret key. So the MD5 hash of the POST vars + your secret key and the signature must match.</p>
<p>In order to use this for authentication, you have to follow these steps:</p>
<ol>
<li>Populate an array of all parameter names as keys and their values</li>
<li>Remove out the signature parameter</li>
<li>Sort the array alphabetically by the key name</li>
<li>Turn the array into a url encoded string</li>
<li>Append your secret key</li>
<li>Compute the MD5 hash with the string</li>
<li>compare your MD5 hash with the signature parameter sent by the Bridge</li>
</ol>
<p>So I prepared this little script that does the job:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// your secret key</span>
<span style="color: #000088;">$key</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;xxxxxxxxxxxxxxxxxxxxxxxxxx&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// initializing an empty string - not strictly necessary</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// ordering the associative POST array by keys</span>
<span style="color: #990000;">ksort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// loop scanning through all POST array</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$varname</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$varvalue</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// if the key is not &quot;signature&quot; then append key and url encoded values to the string</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$varname</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">&quot;signature&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$string</span><span style="color: #339933;">.=</span><span style="color: #000088;">$varname</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$varvalue</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// removing the last character (a &quot;&amp;&quot;&quot;)</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// appeding the secret key to the string</span>
<span style="color: #000088;">$string</span><span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// comparing the md5 encryption of the string with the &quot;signature&quot; variable</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>signature<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// it's a valid submission!</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now you can check for valid submissions, next time I&#8217;ll show you what to do with them</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/08/17/understanding-mochiads-publisher-bridge-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to make a Media RSS feed to help your games compete for SEO</title>
		<link>http://www.emanueleferonato.com/2009/08/06/how-to-make-a-media-rss-feed-to-help-your-games-compete-for-seo/</link>
		<comments>http://www.emanueleferonato.com/2009/08/06/how-to-make-a-media-rss-feed-to-help-your-games-compete-for-seo/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 11:14:10 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Monetize]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1490</guid>
		<description><![CDATA[Hi again, Michael Edlavitch here, ready to give away my secret to improving SEO placement for your games. Just do me a favor and visit my blog, Top Five Blog or Swag Games as your donation :) What is a Media RSS feed? Media RSS was originally created by Yahoo so that people could send [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again, <strong>Michael Edlavitch</strong> here, ready to give away my secret to improving SEO placement for your games. </p>
<p>Just do me a favor and visit my blog, <a target = "_blank" href="http://topfiveblog.com">Top Five Blog</a> or <a target = "_blank" href="http://swaggames.com">Swag Games</a> as your donation :)</p>
<p><strong>What is a Media RSS feed?</strong></p>
<p>Media RSS was originally created by Yahoo so that people could send in there Videos, Images, etc.</p>
<p>More importantly: Google uses MRSS feeds for there Video Search. Google offers a format for  video sitemaps, but those don&#8217;t seem to work like MRSS feeds.</p>
<p>Have you noticed lately, that when you search for a game on google, some sites have a thumbnail image of the game? That is because some arcades are sending in MRSS feeds.</p>
<p>First of all, it took me forever to to figure out how to make one that actually works, reading numerous articles and many attempts. I did this first with <a target = "_blank" href="http://hoodamath.com">Hooda Math</a>, and it took only a few hours for the thumbnails to start showing up, probably because Hooda Math has a PR5.</p>
<p>Recently, I tried it with my sister site to <a href="http://topfiveblog.com" target ="_blank">Top Five Blog</a>, <a target = "_blank" href="http://topfivegames.com">Top Five Games</a>, and it took about a week, but then I noticed my video thumbnails showing up on Google Web Search or at least in there video search.<span id="more-1490"></span></p>
<p>Just today, I took the time to make a MRSS for my newest arcade: <a target = "_blank" href="http://swaggames.com">Swag Games</a>, I&#8217;m pretty excited about this site, because the only Niche is my preferences for games. Finally I get to have some freedom in sponsoring and producing any type of games. So check to see if that MRSS worked in a few days, a week, or a month.</p>
<p>The example I will walk you all through is for &#8220;<a target = "_blank" href="http://www.hoodamath.com/games/linebounder.php">Line Bounder</a>&#8221; a game recently featured on <a href="http://www.addictinggames.com/index.html" target = "_blank">Addicting Games</a> and &#8220;<a target = "_blank" href="http://www.hoodamath.com/games/coffeeshopgame.php">Coffee Shop Game</a>&#8221; which I already had at about #6 on google search, but this bumped it up to #3, plus it now has a thumbnail next to it.</p>
<p>Feel free to google search the games for yourself, they should show up with thumbnails depending where in the world you are located.</p>
<p><img src="/images/coffeeshop.png" alt="" /></p>
<p>Ok, here is an example of the feed.xml I use:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns:media</span>=<span style="color: #ff0000;">&quot;http://search.yahoo.com/mrss/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Math Games<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cool Math Games like Bloxorz, Coffee Shops, Super Stackers 2. Fun Games get you an A Plus in Math.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Thu, 09 Jul 2009 23:00:00 EST<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Line Bounder<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/linebounder.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Line Bounder. Turn based strategy game, your aim is to reach enemy ground and stop him from reaching yours.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/linebounder.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:content</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://hoodamath.com/games/linebounder.swf&quot;</span> <span style="color: #000066;">fileSize</span>=<span style="color: #ff0000;">&quot;981080&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;550&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;550&quot;</span> <span style="color: #000066;">medium</span>=<span style="color: #ff0000;">&quot;video&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Line Bounder<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Line Bounder. Turn based strategy game, your aim is to reach enemy ground and stop him from reaching yours.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:thumbnail</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://www.hoodamath.com/images/g-linebounder.gif&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;160&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;120&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Coffee Shop Game<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/coffeeshopgame.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Coffee Shop Game. Run your own Coffee Shop! You have a limited # of days, so make sure to maximize cash, save inventory, and if you reputation gets high enough you might even get a visit from a special guest. :D<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/coffeeshopgame.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:content</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://hoodamath.com/games/coffeeshop.swf&quot;</span> <span style="color: #000066;">fileSize</span>=<span style="color: #ff0000;">&quot;2080000&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;640&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;480&quot;</span> <span style="color: #000066;">medium</span>=<span style="color: #ff0000;">&quot;video&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Coffee Shop Game<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Coffee Shop Game. Run your own Coffee Shop! You have a limited # of days, so make sure to maximize cash, save inventory, and if you reputation gets high enough you might even get a  
visit from a special guest. <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:thumbnail</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://www.hoodamath.com/images/g-coffeeshop.gif&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;160&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;120&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now I will take you through this step by step.</p>
<p><strong>1) Save it</strong> as <code>feed.xml</code></p>
<p>Let&#8217;s take a closer look at the code</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rss</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns:media</span>=<span style="color: #ff0000;">&quot;http://search.yahoo.com/mrss/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p>Extremely, necessary, since Yahoo came up with the format. Needs to be closed at the end with<br />
<code>&lt;/rss&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You can have these separated into different categories, but I put them all under my main games page, rather than separating them out. Needs to be closed at the end with <code>&lt;/channel&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Math Games<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This is the Title of my Main Games Page.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>this is the URL for my Games page, notice no quotations.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cool Math Games like Bloxorz, Coffee Shops, Super Stackers 2. Fun Games get you an A Plus in Math.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This is the exact same description located in the <code>&lt;meta tag&gt;</code> of my main games page.</p>
<p><strong>IMPORTANT</strong>: Match up as much as possible to please the Google Bots</p>
<p><strong>ALSO</strong>: You still want all of your urls located on your sitemap.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Thu, 09 Jul 2009 23:00:00 EST<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastBuildDate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Again very important to update, every time you change your feed, it is also very hard to get this right, please feel free to copy my format, also the <a href="http://beta.feedvalidator.org/" target = "_blank">FEED Validator</a> I recommend can check this for you.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This will be used for each individual game page. Remember to close each one with <code>&lt;/item&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Line Bounder<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Again, make sure it matches the <code>&lt;title&gt;</code> tags on the URL you are about to add to <code>&lt;item&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/coffeeshopgame.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This is the URL for your page containing the .swf file. Whatever it says in your browser when you go to your game page.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Line Bounder. Turn based strategy game, your aim is to reach enemy ground and stop him from reaching yours.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ok, I know this sounds redundant, but remember to match your <code>&lt;meta  description&gt;</code> and also make sure you have different <code>&lt;meta description&gt;</code> on all of your pages.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://hoodamath.com/games/linebounder.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/guid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I repeated the URL again. Why? I don&#8217;t know, just do it. If you want more details read the Webmonkey link at the bottom of this post.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:content</span> <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;http://hoodamath.com/games/linebounder.swf&quot;</span> <span style="color: #000066;">fileSize</span>=<span style="color: #ff0000;">&quot;981080&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;550&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;550&quot;</span> <span style="color: #000066;">medium</span>=<span style="color: #ff0000;">&quot;video&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Finally we are at the meat of your new MRSS feed.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:content</span></span></pre></div></div>

<p>This <code>&lt;tag&gt;</code> does not use a closing <code>&lt;/tag&gt;</code> all of the info is kept between the <code>&lt;</code> and <code>/&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">url=&quot;http://hoodamath.com/games/linebounder.swf&quot;</pre></div></div>

<p>Now we are finally at the .swf Flash file. Notice how it is in the <code>/games/</code> folder. This is wrong, because I keep it in a <code>/flash/</code> folder, but the MRSS feed seemed to work on Google anyways. I recommend doing it correctly though, and I probably will fix it soon, like in the next year.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">fileSize=&quot;981080&quot;</pre></div></div>

<p>This is the Size of your .swf in bytes. This is optional I think, but I HIGHLY RECOMMEND IT. Give the Google Bots as much information as you can and they are more likely to include your pages in Google Search.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">type=&quot;application/x-shockwave-flash&quot;</pre></div></div>

<p>Just add it, again giving full disclosure to Google, it also probably tells Google, that it needs to be played at your site, rather than in Google Video, this is VERY GOOD for you.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">width=&quot;550&quot; height=&quot;550&quot;</pre></div></div>

<p>Again take the time to give Google as much information as you can.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">medium=&quot;video&quot;</pre></div></div>

<p>Well do you want it in Google Video or not?</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">/&gt;</pre></div></div>

<p>REMEMBER to close up the <code>&lt;tag&gt;</code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Line Bounder<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Just Get use to repeating everything twice, it may work without it, but why take the chance.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Play Line Bounder. Turn based strategy game, your aim is to reach enemy ground and stop him from reaching yours.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/media:description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>repeating twice again&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;media:thumbnail</span></span></pre></div></div>

<p>Oh, So Important, This will be the image that if you are lucky will show up in Google Web Search, with a higher rank than you probably deserve for your game page.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">url=&quot;http://www.hoodamath.com/images/g-linebounder.gif&quot;</pre></div></div>

<p>I would get this right! Also notice I used .gif, I don&#8217;t recommend, because google likes .jpg</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">width=&quot;160&quot; height=&quot;120&quot;</pre></div></div>

<p>These are the minimum dimensions Google states on their site.</p>
<p>I HIGHLY RECOMMEND, you take the time to make a .jpg that is 160&#215;120 and make sure it looks like something you would click.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">/&gt;</pre></div></div>

<p>Again this is a different kind of <code>&lt;tag&gt;</code> so close it up properly. Also, notice everything is contained in quotations.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Finally, close up the <code>&lt;item&gt;</code>, but you aren&#8217;t done on to the next game and the next game.</p>
<p>I included a second example, Coffee Shop Game.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/channel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rss<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>DON&#8217;T FORGET TO CLOSE UP ALL YOUR OPEN &lt;TAGS&gt;</strong></p>
<p><strong>2) Upload it</strong> to the url of your site, for example: <a href="http://hoodamath.com/feed.xml" target = "_blank">http://hoodamath.com/feed.xml</a></p>
<p><strong>3) Validate it</strong> at: <a href="http://beta.feedvalidator.org/" target = "_blank">FEED Validator</a>.</p>
<p><strong>4) Submit it</strong> to Google, Yahoo, and where ever else you want to.</p>
<p>I highly recommend using Google Webmaster Tools to keep track of your MRSS feed&#8217;s progress.</p>
<p>**Sources: I know there was one article out there that was a big help and I believe it was from <a href="http://www.webmonkey.com/tutorial/Use_Media_RSS" target = "_blank">Webmonkey</a>, which can explain each <tag> in more detail. Also Yahoo has a tutorial on Media RSS that even Google Help Recommends.</p>
<p>Now that the secret is out, and there goes a ton of SEO. Please donate by visiting my blog, <a href="http://topfiveblog.com" target ="_blank">Top Five Blog</a> or my new arcade, <a href="http://swaggames.com" target = "_blank">Swag Games</a>, or both.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/08/06/how-to-make-a-media-rss-feed-to-help-your-games-compete-for-seo/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Understanding MochiAds Publisher Bridge</title>
		<link>http://www.emanueleferonato.com/2009/07/16/understanding-mochiads-publisher-bridge/</link>
		<comments>http://www.emanueleferonato.com/2009/07/16/understanding-mochiads-publisher-bridge/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 14:42:58 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1427</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
Now that you have a WordPress theme and plugin in order to set uo your own MochiAds arcade site like triqui.com, let&#8217;s see how we can add some interesting features with the Publisher Bridge. Every step explained in this tutorial will be included in the next upgrade of Triqui MochiAds Arcade theme, but it&#8217;s very [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<p>Now that you have a WordPress <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">theme</a> and <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-plugin-for-wordpress-official-page/">plugin</a> in order to set uo your own <a href="https://www.mochiads.com/r/972ae333a3c92a2a" target = "_blank">MochiAds</a> arcade site like <a href="http://www.triqui.com/" target = "_blank">triqui.com</a>, let&#8217;s see how we can add some interesting features with the Publisher Bridge.</p>
<p>Every step explained in this tutorial will be included in the next upgrade of <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">Triqui MochiAds Arcade  theme</a>, but it&#8217;s very interesting to see how does it work in order to custom it or install it in your own arcade site.</p>
<p>First, let me explain why you should use the Publisher Bridge&#8230; the reasons are listed in the <a href="https://www.mochiads.com/support/pub_docs" target = "_blank">official page</a>:</p>
<ol>
<li>Leverage the hundreds of MochiAds leaderboard enabled games to attract new players.</li>
<li>Receive new traffic &#8211; MochiAds’ Challenges feature will drive new players back to your site to compete in top scores.</li>
<li>Build exciting site features – Save player scoring info for all MochiAds leaderboard-enabled games.</li>
<li>Encourage competition – In-game scores are listed for your community only.</li>
<li>Maintain consistency – Display your own community usernames when players post scores.</li>
<li>Promote your brand – Put your site logo directly in the game.</li>
</ol>
<p>but, as usual, it&#8217;s up to your creativity finding the best way to use them.</p>
<p><strong>Cross-domain policy</strong></p>
<p>From the <a href="http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html" target = "_blank">Cross-domain policy file specification</a> you cana cross-domain policy file is an XML document that grants a web client &#8211; such as Adobe Flash Player (though not necessarily limited to it) &#8211; permission to handle data across multiple domains. When a client hosts content from a particular source domain and that content makes requests directed towards a domain other than its own, the remote domain would need to host a cross-domain policy file that grants access to the source domain, allowing the client to continue with the transaction.</p>
<p>So the first thing you should do is to create a file called <code>crossdomain.xml</code> in your root, with this content:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE cross-domain-policy SYSTEM</span>
<span style="color: #00bbdd;">&quot;http://www.adobe.com/xml/dtds/cross-domain-policy.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cross-domain-policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;site-control</span> <span style="color: #000066;">permitted-cross-domain-policies</span>=<span style="color: #ff0000;">&quot;master-only&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow-access-from</span> <span style="color: #000066;">domain</span>=<span style="color: #ff0000;">&quot;x.mochiads.com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow-access-from</span> <span style="color: #000066;">domain</span>=<span style="color: #ff0000;">&quot;www.mochiads.com&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cross-domain-policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This will allow Mochi client to communicate with your server.</p>
<p><strong>Javascript call</strong></p>
<p>Once your server is able to communicate, you need to insert the javascript provided by Mochi in the same page where you host (or leech) a game.</p>
<p>You don&#8217;t need to know if the game has a leaderboard, if the game does not support highscores, nothing will happen.</p>
<p>This is the one I used:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script src=&quot;http://xs.mochiads.com/static/pub/swf/leaderboard.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
               <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>var options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>partnerID<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;3b7a2ab2368e1d2d&quot;</span><span style="color: #339933;">,</span> id<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;leaderboard_bridge&quot;</span><span style="color: #339933;">,</span>globalScores<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;true&quot;</span><span style="color: #339933;">,</span>gateway <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://www.triqui.com/wp-content/themes/triqui/postscores.php&quot;</span><span style="color: #339933;">,</span>callback <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'latest'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Your latest score: &quot;</span><span style="color: #339933;">+</span>params.<span style="color: #660066;">score</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> Mochi.<span style="color: #660066;">addLeaderboardIntegration</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>I used only a few options among the ones provided by Mochi, let me explain them:</p>
<p><strong>partnerID</strong>: this is the ID <a href="https://www.mochiads.com/r/972ae333a3c92a2a" target = "_blank">MochiAds</a> gave you when you signed up as a publisher. Remember: the Publisher ID, not the Publisher Secret Key!!!</p>
<p><strong>id</strong>: The id of the HTML element you want to place the Bridge SWF into. Place such element wherever you want, it&#8217;s not important since it does not contain anything.</p>
<p><strong>globalScores</strong>: Set to <code>true</code> if you wish to display global scores and not just those submitted from your site. I recommend to set it to <code>true</code> if your portal does not have that much visits per day (under 10,000).</p>
<p><strong>gateway</strong>: the absolute path of a file that will receive posted data with <code>POST</code> method. I&#8217;ll explain how to use such data in next tutorial</p>
<p><strong>callback</strong>: a JavaScript function which will be called when the player submits a score. In my case, I simply display in the page the latest score the player got, but obviously you can use Ajax to improve the interactivity.</p>
<p>Try to see it in action playing a leaderboard enabled game on <a href="http://www.triqui.com/" target = "_blank">Triqui.com</a>, such as <a href="http://www.triqui.com/2009/06/19/mazeroll/" target = "_blank">Mazeroll</a> and see what happens when you submit a score.</p>
<p>But the most exciting feature lies in the gateway: having all score data in the POST array will allow you to create custom leaderboards and some other interesting things I&#8217;ll explain during next tutorial.</p>
<p>Meanwhile, look at the variables the bridge passes to <code>postscores.php</code> page when I submit a score, obtained with a simple <code>var_dump</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="" style="font-family:monospace;">array<span class="br0">&#40;</span><span style="">14</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
  <span class="br0">&#91;</span>&quot;signature&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">32</span><span class="br0">&#41;</span> &quot;<span class="br0">&#40;</span>had to omit it<span class="br0">&#41;</span>&quot;
  <span class="br0">&#91;</span>&quot;sessionID&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">0</span><span class="br0">&#41;</span> &quot;&quot;
  <span class="br0">&#91;</span>&quot;userID&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">0</span><span class="br0">&#41;</span> &quot;&quot;
  <span class="br0">&#91;</span>&quot;username&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">0</span><span class="br0">&#41;</span> &quot;&quot;
  <span class="br0">&#91;</span>&quot;scoreLabel&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">6</span><span class="br0">&#41;</span> &quot;Points&quot;
  <span class="br0">&#91;</span>&quot;sortOrder&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">4</span><span class="br0">&#41;</span> &quot;desc&quot;
  <span class="br0">&#91;</span>&quot;datatype&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">6</span><span class="br0">&#41;</span> &quot;number&quot;
  <span class="br0">&#91;</span>&quot;description&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">0</span><span class="br0">&#41;</span> &quot;&quot;
  <span class="br0">&#91;</span>&quot;title&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">10</span><span class="br0">&#41;</span> &quot;Highscores&quot;
  <span class="br0">&#91;</span>&quot;gameID&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">16</span><span class="br0">&#41;</span> &quot;98c536dbf70a1cbc&quot;
  <span class="br0">&#91;</span>&quot;boardID&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">32</span><span class="br0">&#41;</span> &quot;4b2ac948de239f8853a3bc6a1b771d9d&quot;
  <span class="br0">&#91;</span>&quot;name&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">4</span><span class="br0">&#41;</span> &quot;ququ&quot;
  <span class="br0">&#91;</span>&quot;score&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">3</span><span class="br0">&#41;</span> &quot;<span style="">520</span>&quot;
  <span class="br0">&#91;</span>&quot;lcId&quot;<span class="br0">&#93;</span>=&gt;
  string<span class="br0">&#40;</span><span style="">1</span><span class="br0">&#41;</span> &quot;<span style="">1</span>&quot;
<span class="br0">&#125;</span></pre></td></tr></table></div>

<p>Next time I&#8217;ll show you how to use these values.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/07/16/understanding-mochiads-publisher-bridge/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to generate friendly URLs with .htaccess &#8211; part 2</title>
		<link>http://www.emanueleferonato.com/2008/06/15/how-to-generate-friendly-urls-with-htaccess-part-2/</link>
		<comments>http://www.emanueleferonato.com/2008/06/15/how-to-generate-friendly-urls-with-htaccess-part-2/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 11:52:09 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=292</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
Once you read part 1, you should know how to have a friendly url to play a game in your Flash game portal. In the previous example, I showed you how to transform this link: http://www.triqui.com/play.php?id=1713 into this one: http://www.triqui.com/id/1713/ playing with .htaccess file This is called &#8220;friendly&#8221; url, and now I&#8217;ll show you how [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<p>Once you read <a href="http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/">part 1</a>, you should know how to have a friendly url to play a game in your Flash game portal.</p>
<p>In the previous example, I showed you how to transform this link:</p>
<p><a href="http://www.triqui.com/play.php?id=1713" target = "_blank">http://www.triqui.com/play.php?id=1713</a></p>
<p>into this one:</p>
<p><a href="http://www.triqui.com/id/1713/" target = "_blank">http://www.triqui.com/id/1713/</a></p>
<p>playing with <code>.htaccess</code> file</p>
<p>This is called &#8220;friendly&#8221; url, and now I&#8217;ll show you how to improve it. Starting from&#8230;</p>
<p><strong>Your database game table</strong></p>
<p>There are thousands of ways you can store your games data into your database, but all should follow a rule that in the table that stores your games information you have a column where you saved the game name.</p>
<p>No matter if you called the table &#8220;games&#8221; or &#8220;entries&#8221; or &#8220;bananas&#8221; and you called the column &#8220;game_name&#8221; or &#8220;title&#8221; or &#8220;apples&#8221;&#8230; you should have a table with all games with a column for the game name.<span id="more-292"></span></p>
<p>We can say the &#8220;game_title&#8221; column is a text one (or something that works in the same way) where basically you save stuff like this one:</p>
<p><strong>Jamag</strong>: A simple one-word game name</p>
<p><strong>Pillage the Village</strong>: A more-than-one-word game name</p>
<p><strong>~TimedHouse~</strong>: A game name with one or more special chars, where in this example I am calling &#8220;special char&#8221; every character that is not an alphanumeric one</p>
<p>As every game developer is free to choose the name for his game, we must convert it in our standard way to name games.</p>
<p>There is not a right way or a wrong way, just choose your way.</p>
<p>I&#8217;ll clear this concept with an example. Let&#8217;s Google for a popular game like <a href="http://www.google.com/search?num=100&#038;hl=en&#038;rlz=1T4GGLJ_enIT226IT227&#038;q=desktop+tower+defense" target = "_blank">Desktop Tower Defense</a> and you will notice that, as example, Kongregate&#8217;s urls is this one</p>
<p><a target = "_blank" href="http://www.kongregate.com/games/preecep/desktop-tower-defense-1-5">http://www.kongregate.com/games/preecep/desktop-tower-defense-1-5</a>.</p>
<p>while Jay is Games&#8217; url is</p>
<p><a target = "_blank" href="http://jayisgames.com/archives/2007/06/desktop_tower_defense_15.php">http://jayisgames.com/archives/2007/06/desktop_tower_defense_15.php</a>.</p>
<p>It&#8217;s easy to see that the first one coded the spaces with a <code>-</code> whine the second one coded the spaces with a <code>_</code></p>
<p>So it&#8217;s time to introduce you my own rule:</p>
<p>All non-alphanumeric characters will be removed, with the only exception of spaces that will be changed with a <code>-</code>. The string will be lowercased too.</p>
<p>No matter the rule you will follow, you will have to create a new column in your game table that will contain the &#8220;translated&#8221; name.</p>
<p>The following picture will show the &#8220;game_name&#8221; and the &#8220;translated_game_name&#8221; columns for the last 30 entries</p>
<p><img src="/images/dump.png" alt="" /></p>
<p>once you updated your database, it&#8217;s now time to update your&#8230;</p>
<p><strong>.htaccess file</strong></p>
<p>In the <a href="http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/">previous example</a>, our <code>.htaccess</code> file was</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="" style="font-family:monospace;">ErrorDocument <span style="">404</span> /index.php
RewriteEngine on
RewriteRule ^id/<span class="br0">&#40;</span><span class="br0">&#91;</span>^/\.<span class="br0">&#93;</span>+<span class="br0">&#41;</span>/?$ /play.php?id=$<span style="">1</span> <span class="br0">&#91;</span>L<span class="br0">&#93;</span></pre></td></tr></table></div>

<p>Now it&#8217;s time to add a line in this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="" style="font-family:monospace;">ErrorDocument <span style="">404</span> /index.php
RewriteEngine on
RewriteRule ^id/<span class="br0">&#40;</span><span class="br0">&#91;</span>^/\.<span class="br0">&#93;</span>+<span class="br0">&#41;</span>/?$ /play.php?id=$<span style="">1</span> <span class="br0">&#91;</span>L<span class="br0">&#93;</span>
RewriteRule ^game/<span class="br0">&#40;</span><span class="br0">&#91;</span>^/\.<span class="br0">&#93;</span>+<span class="br0">&#41;</span>/?$ /play.php?game_url=$<span style="">1</span> <span class="br0">&#91;</span>L<span class="br0">&#93;</span></pre></td></tr></table></div>

<p><strong>Line 4</strong>, the new one, acts in the same way as line 3, explained in <a href="http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/">part 1</a>, just waiting for the <code>game</code> string to redirect to<br />
<code>play.php?game_url=translated_game_name</code></p>
<p>and that&#8217;s all for the <code>.htaccess</code></p>
<p>Now, you can play Jamag in four ways:</p>
<p>1) <a href="http://www.triqui.com/play.php?id=1713" target = "_blank">http://www.triqui.com/play.php?id=1713</a></p>
<p>2) <a href="http://www.triqui.com/id/1713/" target = "_blank">http://www.triqui.com/id/1713/</a></p>
<p>3) <a target = "_blank" href="http://www.triqui.com/play.php?game_url=jamag">http://www.triqui.com/play.php?game_url=jamag</a></p>
<p>4) <a target = "_blank" href="http://www.triqui.com/game/jamag/">http://www.triqui.com/game/jamag/</a></p>
<p>As long as your <code>play.php</code> page detects if you are passing the <code>id</code> or <code>game_url</code> variable.</p>
<p>I did this way.</p>
<p>Hope you will find it useful</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/06/15/how-to-generate-friendly-urls-with-htaccess-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to generate friendly URLs with .htaccess</title>
		<link>http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/</link>
		<comments>http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 21:07:51 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=289</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
Ok, now you have your own game portal. Let&#8217;s call it triqui.com. You want to share a link with your friends, or want search engine to index it properly. If I want you to play Jamag, I have to give you this link http://www.triqui.com/play.php?id=1713. Now, I would like you to tell me how can you [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/triqui/public_html/emanueleferonato.com/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<p>Ok, now you have your own game portal. Let&#8217;s call it <a href="http://www.triqui.com/" target = "_blank">triqui.com</a>.</p>
<p>You want to share a link with your friends, or want search engine to index it properly.</p>
<p>If I want you to play Jamag, I have to give you this link<br />
<a href="http://www.triqui.com/play.php?id=1713" target = "_blank">http://www.triqui.com/play.php?id=1713</a>.<br />
Now, I would like you to tell me how can you understand I am talking about Jamag from this link <a href="http://www.triqui.com/play.php?id=1713" target = "_blank">http://www.triqui.com/play.php?id=1713</a>.<br />
You can&#8217;t.</p>
<p>Now let&#8217;s understand why I have to write that <code>play.php?id=xxxx</code> to play a game. </p>
<p>All information about the games is stored in a database, and every game has an unique id assigned by the script.</p>
<p>Jamag&#8217;s id is 1713, so when I pass this value, the php script knows where to retrieve information about the game.</p>
<p>If you want to play Jamag on Kongregate, this is the link:<br />
<a href="http://www.kongregate.com/games/triqui/jamag" target = "_blank">http://www.kongregate.com/games/triqui/jamag</a>.</p>
<p>Seems like Kongregate has a directory to store my games (triqui) and a subdirectory for every game I made.<span id="more-289"></span></p>
<p>Obviously that&#8217;s not true. This is possible thanks to&#8230;</p>
<p><strong>.htaccess file</strong></p>
<p>Normally <code>.htaccess</code> is used to implement custom error pages or password protected directories. But you can do a lot more with this file.</p>
<p>First, let me point that <code>.htaccess</code> is the file extension, not the filename. The filename does not exists.</p>
<p>That&#8217;s what I created with my favourite text editor (notepad&#8230;)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="" style="font-family:monospace;">ErrorDocument <span style="">404</span> /index.php
RewriteEngine on
RewriteRule ^id/<span class="br0">&#40;</span><span class="br0">&#91;</span>^/\.<span class="br0">&#93;</span>+<span class="br0">&#41;</span>/?$ /play.php?id=$<span style="">1</span> <span class="br0">&#91;</span>L<span class="br0">&#93;</span></pre></td></tr></table></div>

<p>Let&#8217;s see what is it:</p>
<p><strong>Line 1</strong>: <code>ErrorDocument</code> detects any document error. If you don&#8217;t know what I am talking about, here it is a brief list:</p>
<p><strong>401</strong>: Unauthorized &#8211; The request requires user authentication. </p>
<p><strong>403</strong>: Forbidden &#8211; The server understood the request, but is refusing to fulfill it.</p>
<p><strong>404</strong>: Not Found &#8211; The server has not found anything matching the Request-URI.</p>
<p>So <strong>ErrorDocument 404</strong> refers to a &#8220;not found&#8221; error&#8230; that happens when the user looks for a page that does not exist</p>
<p><code>/index.php</code> is the path where to redirect the user if he requested a page that does not exist</p>
<p>We can say that <code>ErrorDocument 404 /index.php</code> means &#8220;if someone requested a page that does not exist, then redirect him to index.php&#8221;.</p>
<p>And that&#8217;s what happens: go to <a href="http://www.triqui.com/dfgretre" target = "_blank">http://www.triqui.com/dfgretre</a> (a page that does not exist) and you will be redirected to home page.</p>
<p>Just in one line of code&#8230;</p>
<p><strong>Line 2</strong>: Activation of the <code>RewriteEngine</code> module, a rewriting engine to rewrite requested URLs on the fly.</p>
<p>Not all servers support the rewrite engine.</p>
<p>In order to determine if your server supports it, you have to upload a php file with just:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">phpinfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>and see what happens. In the result page, search for &#8220;mod_rewrite&#8221;.</p>
<p>If you find it in the &#8220;Apache loaded modules&#8221; section, then you know your server supports the rewrite engine, although in a server with php version 4.4.7 I was able to make it work even if the search returned a negative result.</p>
<p><strong>Line 3</strong>: The core instruction: <code>RewriteRule</code> looks if the current URL matches with the regular expression passed as first parameter.</p>
<p>That <code>^id/([^/\.]+)/?$</code> is a regular expression, and even if I am planning to make a tutorial about regular expressions (reg exps from now on), at the moment I am just recommending you this <a target = "_blank" href="http://en.wikipedia.org/wiki/Regular_expression">Wikipedia article</a>.</p>
<p>The second parameter of <code>RewriteRule</code> is the substitution.</p>
<p>Basically this instruction says: if the page starts with <code>id</code> (<code>^id/</code>) then copy everything that&#8217;s not a slash, a backslash or a period (<code>([^/\.]+)</code>) and make sure that after the starting matched <code>id</code> there is only a slash (<code>/?$</code>)&#8230; then load the page <code>/play.php?id=$1</code>, pasting the characters previously copied in place of $1.</p>
<p>The final <code>[L]</code> tells not to search for any more rule if this one was satisfied.</p>
<p>In an even basic way, the script says:</p>
<p>If you find an URL like<br />
<a href="http://www.triqui.com/id/1713/" target = "_blank">http://www.triqui.com/id/1713/</a><br />
just redirect to URL<br />
<a href="http://www.triqui.com/play.php?id=1713" target = "_blank">http://www.triqui.com/play.php?id=1713</a></p>
<p>And that&#8217;s what happens if you go to <a href="http://www.triqui.com/id/1713/" target = "_blank">http://www.triqui.com/id/1713/</a>.</p>
<p>I hust had to upload that <code>.htaccess</code> file in my root directory.</p>
<p>You may say there is not a big difference between <code>play.php?id=1713</code> and <code>/id/1713/</code> but this is the first step to friendly URLs generation.</p>
<p>Stay tuned for the next update.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/06/10/how-to-generate-friendly-urls-with-htaccess/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
