<?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>Maribol Labs</title>
	<atom:link href="http://www.mlabs.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mlabs.info</link>
	<description>Programming and Design Blog</description>
	<lastBuildDate>Mon, 28 Nov 2011 07:41:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Add error image when a image is not found</title>
		<link>http://www.mlabs.info/add-error-image/</link>
		<comments>http://www.mlabs.info/add-error-image/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 12:18:35 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[404 error]]></category>
		<category><![CDATA[image not found]]></category>
		<category><![CDATA[jquery tutorial]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=1077</guid>
		<description><![CDATA[When creating a website, a priority is to make your website load faster. That&#8217;s good! But what are you doing if your website is embeding some images who doesn&#8217;t exist? Example: View Code HTML&#60;img src=&#34;http://example.com/my-image.jpg&#34;&#62; If the image (my-image.jpg in our example) doesn&#8217;t exist, your website will get loaded more slowly but if you user [...]]]></description>
			<content:encoded><![CDATA[<p>When creating a website, a priority is to make your website load faster. <b>That&#8217;s good!</b><br />
But what are you doing if your website is embeding some images who doesn&#8217;t exist?</p>
<p><b>Example:</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1077code3'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10773"><td class="code" id="p1077code3"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://example.com/my-image.jpg&quot;&gt;</pre></td></tr></table></div>

<p>If the image <em>(my-image.jpg in our example)</em> doesn&#8217;t exist, your website will get loaded more slowly but if you user the .error event from jQuery you can solve this problem easily.</p>
<p>Example:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1077code4'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10774"><td class="code" id="p1077code4"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://example.com/image-not-found.jpg);
	});
});</span></pre></td></tr></table></div>

<p>So this script changes the image source to the error image <em>(image-not-found.jpg) in our example)</em> and your should not have any problem visiting your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/add-error-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First post in &#8220;A day in the life of a developer&#8221;</title>
		<link>http://www.mlabs.info/post-a-day-life-developer/</link>
		<comments>http://www.mlabs.info/post-a-day-life-developer/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 08:34:19 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[A day in the life of a developer]]></category>
		<category><![CDATA[developer life]]></category>
		<category><![CDATA[maribol]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[romanian]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=1065</guid>
		<description><![CDATA[Lately i started to write more in English and Romanian and i just tinked that i should write something about how i spend my days as a web developer. If you would like to know that someone reads my articles and it will be a pleasure for me to write. I also write in Romanian [...]]]></description>
			<content:encoded><![CDATA[<p>Lately i started to write more in English and Romanian and i just tinked that i should write something about how i spend my days as a web developer.<br />
If you would like to know that someone reads my articles and it will be a pleasure for me to write.<br />
<a target="_blank" href="http://www.mlabs.info/wp-content/uploads/2011/11/on_12_october_by_maribol-d4cm01o.jpg"><img src="http://www.mlabs.info/wp-content/uploads/2011/11/on_12_october_by_maribol-d4cm01o-150x150.jpg" alt="" title="Samuel Marian" width="150" height="150" class="alignright size-thumbnail wp-image-1067" /></a></p>
<p>I also write in Romanian sometimes on my other blog <a target="_blank" href="http://www.maribol.ro" target="_blank">Maribol.ro &#8211; Blog &#038; Photo</a>.</p>
<p>Anyway this is my first personal blog post here so i&#8217;d like to know that somebody reads what i write and tell me their opinion.</p>
<p>I&#8217;m that guy from the right side of this post so that you know who do you read.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/post-a-day-life-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a Move Up and Move Down button using jQuery</title>
		<link>http://www.mlabs.info/create-move-move-button-jquery/</link>
		<comments>http://www.mlabs.info/create-move-move-button-jquery/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 11:44:22 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=1044</guid>
		<description><![CDATA[I&#8217;m sorry i haven&#8217;t posted new tutorials for a long time. And very soon i&#8217;ll update the wordpress plugin Maribol IMDB. So what i would like to teach you today is how to move an element using the powerfull jQuery. Let&#8217;s asume that you want to order the order for some text inputs HTML structure: [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sorry i haven&#8217;t posted new tutorials for a long time.<br />
And very soon i&#8217;ll update the <a href="http://www.mlabs.info/maribol-imdb/" target="_blank">wordpress plugin Maribol IMDB</a>.</p>
<p>So what i would like to teach you today is how to move an element using the powerfull jQuery.</p>
<p>Let&#8217;s asume that you want to order the order for some text inputs</p>
<p>HTML structure:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1044code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10447"><td class="code" id="p1044code7"><pre class="html" style="font-family:monospace;">&lt;div&gt;
    &lt;div&gt;
        &lt;input type=&quot;text&quot; name=&quot;values[]&quot; value=&quot;value 1&quot;&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveUp&quot;&gt;&amp;uarr;&lt;/a&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveDown&quot;&gt;&amp;darr;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;input type=&quot;text&quot; name=&quot;values[]&quot; value=&quot;value 2&quot;&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveUp&quot;&gt;&amp;uarr;&lt;/a&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveDown&quot;&gt;&amp;darr;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;input type=&quot;text&quot; name=&quot;values[]&quot; value=&quot;value 3&quot;&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveUp&quot;&gt;&amp;uarr;&lt;/a&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveDown&quot;&gt;&amp;darr;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;input type=&quot;text&quot; name=&quot;values[]&quot; value=&quot;value 4&quot;&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveUp&quot;&gt;&amp;uarr;&lt;/a&gt;
        &lt;a href=&quot;javascript:;&quot; class=&quot;moveDown&quot;&gt;&amp;darr;&lt;/a&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>Javascript:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1044code8'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10448"><td class="code" id="p1044code8"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.moveUp'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> current <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            current.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span>current<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.moveDown'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> current <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            current.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span>current<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a href="http://www.mlabs.info/wp-content/uploads/2011/11/demo.html" target="_blank">View demo here</a></p>
<p>If you have any question please leave them in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/create-move-move-button-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AJAX and PHP together</title>
		<link>http://www.mlabs.info/ajax-php/</link>
		<comments>http://www.mlabs.info/ajax-php/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 18:21:58 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=922</guid>
		<description><![CDATA[In this tutorial i&#8217;ll show you how to use PHP and AJAX together and get the results that you need. Here&#8217;s an example of a function that executes a ajax request View Code JAVASCRIPTfunction execAjax&#40;type&#41;&#123; $.ajax&#40;&#123; url: 'ajax.php?type='+type, dataType: 'json', success: function&#40; data &#41; &#123; var items = &#91;&#93;; &#160; $.each&#40;data, function&#40;key, val&#41; &#123; items.push&#40;'&#60;li [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial i&#8217;ll show you how to use PHP and AJAX together and get the results that you need.</p>
<p><b>Here&#8217;s an example of a function that executes a ajax request</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code14'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92214"><td class="code" id="p922code14"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> execAjax<span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax.php?type='</span><span style="color: #339933;">+</span>type<span style="color: #339933;">,</span>
      dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
      success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> items <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
         $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            items.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;li id=&quot;'</span> <span style="color: #339933;">+</span> key <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> val <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#results'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;ul/&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #3366CC;">'class'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'results-list'</span><span style="color: #339933;">,</span>
               html<span style="color: #339933;">:</span> items.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
         <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This function should add a list with all the items resulted from the request.</p>
<p><b>Example of use:</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code15'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92215"><td class="code" id="p922code15"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('fruits')&quot;&gt;fruits&lt;/a&gt;
&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('vegetables')&quot;&gt;vegetables&lt;/a&gt;
&lt;a href=&quot;javascript:;&quot; onclick=&quot;execAjax('furniture')&quot;&gt;furniture&lt;/a&gt;
&nbsp;
&lt;div id=&quot;results&quot;&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>And the ajax.php return an array encoded in json.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92216"><td class="code" id="p922code16"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'fruits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'bannana'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'orange'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'vegetables'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'potato'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'onion'</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'furniture'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'chair'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'desk'</span>
   <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If we&#8217;ve clicked on the &#8220;fruits&#8221; link, will get a result like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code17'); return false;">View Code</a> JSON</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92217"><td class="code" id="p922code17"><pre class="json" style="font-family:monospace;">[&quot;apple&quot;,&quot;bannana&quot;,&quot;orange&quot;]</pre></td></tr></table></div>

<p>This encoded array will be transformed in list with the &#8220;each&#8221; function from jquery and the result that you should see is:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p922code18'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92218"><td class="code" id="p922code18"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;results&quot;&gt;
   &lt;ul class=&quot;results-list&quot;&gt;
      &lt;li id=&quot;0&quot;&gt;apple&lt;/li&gt;
      &lt;li id=&quot;1&quot;&gt;bannana&lt;/li&gt;
      &lt;li id=&quot;2&quot;&gt;orange&lt;/li&gt;
   &lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/ajax-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Tutorial #2: Are you protected against sql injections?</title>
		<link>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/</link>
		<comments>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 12:34:42 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[anti sql injection]]></category>
		<category><![CDATA[mysql_real_escape_string]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[stripslashes]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=965</guid>
		<description><![CDATA[There are alot of websites that are vulnerable to sql injections. In this tutorial i&#8217;ll give you some examples with methods to protect you website. &#160; Make your id from url (int) Let&#8217;s assume that you get the id like this: View Code PHP $id = $_GET&#91;'id'&#93;; Well with this, your site may be vulnerable. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png"><img src="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png" alt="" title="Security Centre" width="128" height="128" class="alignleft size-full wp-image-957" /></a>There are alot of websites that are vulnerable to sql injections.<br />
In this tutorial i&#8217;ll give you some examples with methods to protect you website.</p>
<div style="clear:both;"></div>
<p>&nbsp;</p>
<p><strong>Make your id from url <em>(int) </em></strong></p>
<p>Let&#8217;s assume that you get the id like this:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96523"><td class="code" id="p965code23"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well with this, your site may be vulnerable.</p>
<p>But if you use like this it will never be vulerable from this variable:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96524"><td class="code" id="p965code24"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Basically this will make your id an id, i mean the value returned is always numeric.</p>
<p>&nbsp;</p>
<p><strong>Use the <em>mysql_real_escape_string</em> function</strong><br />
This function may help you alot!</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96525"><td class="code" id="p965code25"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT firstname, lastname FROM people WHERE city=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Note:</strong> if <em>magic_quotes_gpc</em> is enabled you should use:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p965code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p96526"><td class="code" id="p965code26"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'city'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT firstname, lastname FROM people WHERE city=&quot;'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$city</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/security-tutorial-2-protected-sql-injections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maribol Personal &#8211; WordPress Theme</title>
		<link>http://www.mlabs.info/maribol-personal-wordpress-theme/</link>
		<comments>http://www.mlabs.info/maribol-personal-wordpress-theme/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 22:16:09 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[Themes]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[free wordpress theme]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=969</guid>
		<description><![CDATA[Maribol Personal is a free wordpress theme with a very simple design but it looks pretty. Demo: here Download: here]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mlabs.info/wp-content/uploads/2011/07/screenshot.png"><img class="alignleft size-full wp-image-971" title="screenshot" src="http://www.mlabs.info/wp-content/uploads/2011/07/screenshot.png" alt="" width="300" height="225" /></a>Maribol Personal is a <strong>free wordpress theme</strong> with a very simple design but it looks pretty.</p>
<p>Demo: <a target="_blank" href="http://etiny.info/unjcg" target="_blank">here</a></p>
<p>Download: <a target="_blank" href="http://cl.ly/8VS2" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/maribol-personal-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Security Tutorial #1: Password hashing</title>
		<link>http://www.mlabs.info/security-tutorial-1-password-hashing/</link>
		<comments>http://www.mlabs.info/security-tutorial-1-password-hashing/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 15:10:23 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[salt]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=953</guid>
		<description><![CDATA[In the past two years i&#8217;ve used many methods to hash a password. The best method i used is by adding a salt and then encrypting with md5. If you encrypt a password without a salt is more easily (but almost impossible) to find the password. It&#8217;s important to know that if you want to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png"><img src="http://www.mlabs.info/wp-content/uploads/2011/07/Security-Centre.png" alt="" title="Security Centre" width="128" style="border:none;" height="128" class="alignleft size-full wp-image-957" /></a>
<p>In the past two years i&#8217;ve used many methods to hash a password. The best method i used is by adding a salt and then encrypting with md5.</p>
<p>If you encrypt a password without a salt is more easily <em>(but almost impossible)</em> to find the password.</p>
<p>It&#8217;s important to know that if you want to make a login system you have to chose a salt and never change it.</p>
<p>An example how to encrypt:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p953code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p95328"><td class="code" id="p953code28"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'!@#$%^&amp;*()_+'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">.</span><span style="color: #000088;">$salt</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>This code should result and md5 string like:<br />
<b>bbadaec5c53ce3065d14cbe938640088</b></p>
<p><strong>This is the first tutorial in a series of tutorials dedicated to your site security</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/security-tutorial-1-password-hashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maribol IMDB &#8211; WordPress Plugin</title>
		<link>http://www.mlabs.info/maribol-imdb/</link>
		<comments>http://www.mlabs.info/maribol-imdb/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 20:21:24 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[imdb]]></category>
		<category><![CDATA[imdb plugin]]></category>
		<category><![CDATA[wordpress movie]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=930</guid>
		<description><![CDATA[Maribol IMDB is a wordpress plugin that helps you show info about a movie in your blog posts. Example of usage: View Code BBCODE[imdb]tt1399103[/imdb] &#60;b&#62;Title:&#60;/b&#62; [imdb:title] ([imdb:year]) &#60;b&#62;Duration:&#60;/b&#62; [imdb:duration] &#60;b&#62;Director:&#60;/b&#62; [imdb:director] And the result should be: View Code HTML&#60;b&#62;Title:&#60;/b&#62; Transformers: Dark of the Moon (2011) &#60;b&#62;Duration:&#60;/b&#62; USA: 157 min &#60;b&#62;Director:&#60;/b&#62; Michael Bay Available Fields View [...]]]></description>
			<content:encoded><![CDATA[<p>Maribol IMDB is a wordpress plugin that helps you show info about a movie in your blog posts.</p>
<p>Example of usage:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p930code32'); return false;">View Code</a> BBCODE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p93032"><td class="code" id="p930code32"><pre class="bbcode" style="font-family:monospace;">[imdb]tt1399103[/imdb]
&lt;b&gt;Title:&lt;/b&gt; [imdb:title] ([imdb:year])
&lt;b&gt;Duration:&lt;/b&gt; [imdb:duration]
&lt;b&gt;Director:&lt;/b&gt; [imdb:director]</pre></td></tr></table></div>

<p>And the result should be:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p930code33'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p93033"><td class="code" id="p930code33"><pre class="html" style="font-family:monospace;">&lt;b&gt;Title:&lt;/b&gt; Transformers: Dark of the Moon (2011)
&lt;b&gt;Duration:&lt;/b&gt; USA: 157 min
&lt;b&gt;Director:&lt;/b&gt; Michael Bay</pre></td></tr></table></div>

<p><b>Available Fields</b></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p930code34'); return false;">View Code</a> BBCODE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p93034"><td class="code" id="p930code34"><pre class="bbcode" style="font-family:monospace;">[imdb:title]
[imdb:year]
[imdb:description]
[imdb:short_description] // since 0.2 version
[imdb:poster]
[imdb:poster_small] // since 0.3 version
[imdb:duration]
[imdb:categories]
[imdb:director]
[imdb:cast]
[imdb:writers]
[imdb:language]
[imdb:release_date]
[imdb:filming_locations]
[imdb:rating] // since 0.3 version</pre></td></tr></table></div>

<p>Download this plugin at <a target="_blank" href="http://wordpress.org/extend/plugins/maribol-imdb" target="_blank">WordPress.org</a></p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Hfly-jIJKdI?fs=1&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="550" height="385" src="http://www.youtube.com/v/Hfly-jIJKdI?fs=1&amp;hl=en_US" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/maribol-imdb/feed/</wfw:commentRss>
		<slash:comments>128</slash:comments>
		</item>
		<item>
		<title>Transform image to Base64</title>
		<link>http://www.mlabs.info/transform-image-base64/</link>
		<comments>http://www.mlabs.info/transform-image-base64/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 18:36:57 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[image in email]]></category>
		<category><![CDATA[image to base64]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=914</guid>
		<description><![CDATA[Lately i&#8217;ve seen very often in email newsletters images embed with base64. If you send email newsletters containing image, this is the best way to send. First we try to open the file. View Code PHP $file_path = 'my-image.jpg'; if&#40;$fp = fopen&#40;$file,&#34;rb&#34;, 0&#41;&#41;&#123; &#125;else&#123; echo 'Can\'t open file'; &#125; If the file exist and we [...]]]></description>
			<content:encoded><![CDATA[<p>Lately i&#8217;ve seen very often in email newsletters images embed with base64.<br />
If you send email newsletters containing image, this is the best way to send.</p>
<p>First we try to open the file.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code39'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91439"><td class="code" id="p914code39"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my-image.jpg'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;rb&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Can\'t open file'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If the file exist and we have all the rights we need to open it, we read the binary data.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code40'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91440"><td class="code" id="p914code40"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$picture</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>After we have the binary data of the image wi&#8217;ll encode it to base64 and then break it into chunks according to RFC 2045 semantics and we display the html code in a textarea.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code41'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91441"><td class="code" id="p914code41"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$base64</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$picture</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$tag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;textarea style=&quot;width:400px;height:300px;&quot;&gt;&lt;img src=&quot;data:image/jpg;base64,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$base64</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;  /&gt;&lt;/textarea&gt;'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>..and the final code:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p914code42'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91442"><td class="code" id="p914code42"><pre class="php" style="font-family:monospace;">   <span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my-image.jpg'</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;rb&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$picture</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$base64</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$picture</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$tag</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;textarea style=&quot;width:400px;height:300px;&quot;&gt;&lt;img src=&quot;data:image/jpg;base64,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$base64</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;  /&gt;&lt;/textarea&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tag</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: #b1b100;">echo</span> <span style="color: #0000ff;">'Can\'t open file'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/transform-image-base64/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to make a search engine on your site. The good method.</title>
		<link>http://www.mlabs.info/search-engine-site-good-method/</link>
		<comments>http://www.mlabs.info/search-engine-site-good-method/#comments</comments>
		<pubDate>Tue, 31 May 2011 18:35:58 +0000</pubDate>
		<dc:creator>Samuel Marian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[search engine]]></category>

		<guid isPermaLink="false">http://www.mlabs.info/?p=890</guid>
		<description><![CDATA[Okay, so many people think that if you make a search engine on your site with query like the one below, it&#8217;s okay. View Code SQLSELECT id,name,post FROM posts WHERE name LIKE '%my key%' But it&#8217;s not! Because: Let&#8217;s assume that you have a post called: My little post name If you make a search [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so many people think that if you make a search engine on your site with query like the one below, it&#8217;s okay.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code51'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89051"><td class="code" id="p890code51"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my key%'</span></pre></td></tr></table></div>

<p><b>But it&#8217;s not!</b> </p>
<p>Because:<br />
Let&#8217;s assume that you have a post called: <em>My little post name</em></p>
<p>If you make a search in your database like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code52'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89052"><td class="code" id="p890code52"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%little post%'</span></pre></td></tr></table></div>

<p>you will get a result.</p>
<p>But if you make a search in your database like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code53'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89053"><td class="code" id="p890code53"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my post%'</span></pre></td></tr></table></div>

<p>you will not get any result.</p>
<p>Okay so the method i use is like this:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code54'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89054"><td class="code" id="p890code54"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span>name<span style="color: #66cc66;">,</span>post <span style="color: #993333; font-weight: bold;">FROM</span> posts <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#40;</span>name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%my%'</span> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%post%'</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>and this query will get a result.</p>
<p><b>How to do:</b></p>
<p>First we split the string by space with the explode() function and the result is an array with two items.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code55'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89055"><td class="code" id="p890code55"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'my post'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>After that, we use the implode() function to create the condition</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code56'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89056"><td class="code" id="p890code56"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' AND name LIKE &quot;%'</span><span style="color: #339933;">.</span><span style="color: #000088;">$item</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'%&quot;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$addToQuery</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above code should result something like:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code57'); return false;">View Code</a> SQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89057"><td class="code" id="p890code57"><pre class="sql" style="font-family:monospace;"> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">&quot;%my%&quot;</span> <span style="color: #993333; font-weight: bold;">AND</span> name <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">&quot;%post%&quot;</span></pre></td></tr></table></div>

<p>Now we have to add this string to SQL Query:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p890code58'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p89058"><td class="code" id="p890code58"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT id,name,post FROM posts WHERE 1 '</span><span style="color: #339933;">.</span><span style="color: #000088;">$addToQuery</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' ORDER BY id DESC'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mlabs.info/search-engine-site-good-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.mlabs.info @ 2012-02-04 17:21:51 -->
