<?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>Web Development Blog</title>
	<atom:link href="http://www.web-development-blog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-development-blog.com</link>
	<description>Web development tutorials, SEO articles and PHP script resources</description>
	<lastBuildDate>Thu, 25 Feb 2010 18:36:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Your e-mail address hidden with jQuery?</title>
		<link>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/</link>
		<comments>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 17:35:17 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=918</guid>
		<description><![CDATA[Last week we published an article with different methods to hide e-mail addresses on websites. Because of several comments with suggestions on how-to solve this problem, we provide this week a solution which is &#8220;from these days&#8221; and more powerful.
Based on the idea if you don&#8217;t show an address, a spambot can&#8217;t see it, we [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>Last week we published an article with different methods to <a href="http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/">hide e-mail addresses</a> on websites. Because of several comments with suggestions on how-to solve this problem, we provide this week a solution which is &#8220;from these days&#8221; and more powerful.</p>
<p>Based on the idea if you don&#8217;t show an address, a spambot can&#8217;t see it, we use in our example a simple Ajax call (using jQuery) and show a tiny box with some friendly message including the link with e-mail address.<br />
<strong>DEMO:</strong> We used the code from this tutorial on the this <a href="http://www.finalwebsites.com/web_hosting_promotion.php" title="Webfaction hosting">page</a>.</p>
<h3>How does it work?</h3>
<p>First we need to create a simple php file that holds the content and the e-mail address, we use json_encode to make the string less readable:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// change the two vars below</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'user@mail.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Please contact us by e-mail: &lt;a href=&quot;mailto:%%mAdr%%&quot;&gt;%%mAdr%%&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;a href=&quot;javascript:void(0);&quot; id=&quot;hideme&quot;&gt;Close&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$eparts</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: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ename'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$eparts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dom'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$eparts</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: #0000ff;">'htmlcode'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Don&#8217;t forget to block that file in your robots.txt file!<span id="more-918"></span></p>

<p>Now we need a function that will load the external content into the current page using an Ajax request.</p>

<div class="wp_syntax"><div class="code"><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;">&quot;#clickme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</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: #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;">'glink.html'</span><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> adr <span style="color: #339933;">=</span> data.<span style="color: #660066;">ename</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'@'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">domain</span><span style="color: #339933;">;</span>
	  			<span style="color: #003366; font-weight: bold;">var</span> newdata <span style="color: #339933;">=</span> data.<span style="color: #660066;">htmlcode</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/%%mAdr%%/g</span><span style="color: #339933;">,</span> adr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span#ajaxresp'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>newdata<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hideme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</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;">&quot;span#ajaxresp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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></div></div>

<h3>jQuery code in detail</h3>
<p>A visitor has clicked the element with the ID &#8220;clickme&#8221; and the Ajax request for the file &#8220;glink.php&#8221; is done. On &#8220;success&#8221; parse the html string with the two other json pairs and add the result to the SPAN element with ID &#8220;ajaxresp&#8221; is filled with the response from the external file and the box will slide down. To make the elements from the Ajax content accessible, we use &#8220;live()&#8221; events instead of the &#8220;regular&#8221; click event.<br />
The visitor need to click the element with ID &#8220;hideme&#8221; to slide an empty &#8220;Ajax box&#8221; back to the original position.</p>
<p>Additional we give our dynamic email box some style using CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">span<span style="color: #cc00cc;">#ajaxresp</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCCCCC</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EDECEB</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The following code holds the &#8220;contact&#8221; link which is using the click event and the small container where the Ajax response data is placed.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:void(0);&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clickme&quot;</span>&gt;</span>Contact<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ajaxresp&quot;</span>&gt;</span></pre></div></div>

<p>If your visitor has clicked this &#8220;contact&#8221; link the following box appears:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2010/02/jquery-slide-down.png" rel="shadowbox[post-918];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2010/02/jquery-slide-down-300x99.png" alt="" title="jquery-slide-down" width="300" height="99" class="alignnone size-medium wp-image-919" /></a></p>
<p>If you have the jQuery and CSS code in external files, it&#8217;s possible to use the function on all your pages. The best thing is that the loaded box has also room for a personal message for your visitor. It&#8217;s just a simple solution without the need of building a contact form. This was the third article of a series with solutions on how-to add the contact information to your article or website.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/" rel="bookmark" title="February 15, 2010">E-mail links, protective solutions against SPAM</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
</ul>
<p><!-- Similar Posts took 3.300 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>E-mail links, protective solutions against SPAM</title>
		<link>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/</link>
		<comments>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:14:38 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[protect]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=884</guid>
		<description><![CDATA[If you place your e-mail address somewhere visible on your website, it will be only a matter of time until your e-mail account will get more and more spam messages. There are lots of spam bots checking the Internet for email addresses on regular websites, forums, blog and mailing lists. Once caught by some spam [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div style="float: left; width: 42px; padding-right: 115px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/";
		var dzone_title = "E-mail links, protective solutions against SPAM";
		var dzone_style = "2";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p>If you place your e-mail address somewhere visible on your website, it will be only a matter of time until your e-mail account will get more and more spam messages. There are lots of spam bots checking the Internet for email addresses on regular websites, forums, blog and mailing lists. Once caught by some spam bot your mailbox is in need of a strong spam filter or sometimes it might be better to use a new e-mail address.</p>

<p>In this article we show you different ways, how you&#8217;re able to show your e-mail address to human visitors and hide it for spam bots. </p>
<blockquote><p><strong>Don&#8217;t forget</strong>, the solutions mentioned in this article are not a total protection against spam. If you share your e-mail address online, the chance that your e-mail address get on a spammer&#8217;s list is big. We advice that if you need to share an e-mail address with your websites&#8217;s visitor, to not use your personal e-mail address.</p></blockquote>
<p>With each solution we give a review for:</p>
<ul>
<li><strong>Integration:</strong> Is this function easy to integrate even for a less experienced webmaster.</li>
<li><strong>Protection:</strong> Is the e-mail address protected against spam bots.</li>
<li><strong>User friendly:</strong> Is the solution easy to use for a website&#8217;s visitor</li>
</ul>
<h3>The simple solution, an image from your e-mail address</h3>
<p>Just providing image version is very simple and easy. Open your image editor, create a small image from your email address and upload the image to your website.<br />
<img src="http://www.web-development-blog.com/wp-content/uploads/2010/02/email.png" alt="" title="email" width="116" height="16" class="alignnone size-full wp-image-907" /><br />
After this you&#8217;re able to place that address in to the HTML, just on that place where you need it. It&#8217;s safe for your e-mail address and it&#8217;s simple to use that image in your website document or CMS. There is one big issue with this solution: The visitor has to type over your e-mail address to his e-mail program.<span id="more-884"></span></p>
<h3>Hide the @ symbol</h3>
<p>There are different ways to hide the format of an e-mail address. Hoe does this work? Changing the format of some email address or just hiding parts from the e-mail address makes it more difficult for spam bots to find them. For example:</p>
<ol>
<li>user&amp;#64;email.com</li>
<li>user at email dot com</li>
</ol>
<p>While the first one is very webmaster friendly, it&#8217;s not be the best protection for your e-mail address. The second example is used very often because this &#8220;faked&#8221; address is easy to add to your content. Both formats are recognized by smarter spam bots.</p>
<h3>Hide your e-mail address using PHP</h3>
<p>The following example will convert the string of some e-mail adress into unicode values:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> convert_email_adr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$pieces</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$new_mail</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;">$pieces</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$new_mail</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&amp;#'</span><span style="color: #339933;">.</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_mail</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use this function in your web page like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> convert_email_adr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user@email.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The output in your html is like:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #ddbb00;">&amp;#117;&amp;#115;&amp;#101;&amp;#114;&amp;#64;&amp;#101;&amp;#109;&amp;#97;&amp;#105;&amp;#108;&amp;#46;&amp;#99;&amp;#111;&amp;#109;</span></pre></div></div>

<p>This way the e-mail address is visible to the visitor like normal. Using this format for a mailto: link will open a new window from the visitor&#8217;s e-mail program. There might be a few spam bots which are able to read this format as well.</p>
<h3>Some JavaScript solution</h3>
<p>The last solution is very similar to the PHP snippet and requires similar handling to add some email link to your website. Place the following function into your HTML document or include the code as an external JS file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><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>
<span style="color: #003366; font-weight: bold;">function</span> create_mail<span style="color: #009900;">&#40;</span>naam<span style="color: #339933;">,</span> domain<span style="color: #339933;">,</span> tld<span style="color: #339933;">,</span> label<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> mail<span style="color: #339933;">;</span>
    mail <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&lt;a href=&quot;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'ma'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'il'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'to:'</span> <span style="color: #339933;">+</span> naam<span style="color: #339933;">;</span>
    mail <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;#64;'</span> <span style="color: #339933;">+</span> mail <span style="color: #339933;">+</span> domain <span style="color: #3366CC;">'.'</span> <span style="color: #339933;">+</span> tld<span style="color: #339933;">;</span>
    mail <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> label <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'/a&gt;'</span><span style="color: #339933;">;</span>
    document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span>mail<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Use this code inside the website content:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><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>create_mail<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;email&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;com&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;e-mail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This method is very protective against spam bots, but will not work if JavaScript is disabled in the visitors browser. On the other site this code is very flexible and easy to use.</p>
<p>You see there are many different ways to add your e-mail address to your website without to expose the it to spam bots. If you search Google you will find much more examples, some of them are safe and some of them might have a better usability. If you don&#8217;t like to show your email address you should use a <a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/">contact form</a> on your website. If you know some great and easy function to hide an e-mail address in HTML code, please post it below. <strong>If you like this article please share the link on twitter or facebook, thanks.</strong><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/" rel="bookmark" title="February 25, 2010">Your e-mail address hidden with jQuery?</a></li>
<li><a href="http://www.web-development-blog.com/archives/attachment-mailer-class-now-support-for-html-mail/" rel="bookmark" title="November 13, 2006">Attachment Mailer class: now support for HTML mail</a></li>
</ul>
<p><!-- Similar Posts took 3.218 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Google Custom Search in a Lightbox!</title>
		<link>http://www.web-development-blog.com/archives/google-custom-search-in-a-lightbox/</link>
		<comments>http://www.web-development-blog.com/archives/google-custom-search-in-a-lightbox/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 08:42:33 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[Google services]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=869</guid>
		<description><![CDATA[There are several tutorials on the Internet on how-to integrate the Google Custom search in your website, but the results are not very attractive. The older iframe version doesn&#8217;t fit perfectly in most of our templates and the style for ads and results doesn&#8217;t look good in the past. A few month Google has released [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>There are several tutorials on the Internet on how-to integrate the Google Custom search in your website, but the results are not very attractive. The older iframe version doesn&#8217;t fit perfectly in most of our templates and the style for ads and results doesn&#8217;t look good in the past. A few month Google has released some nice new features:</p>
<ul>
<li>Custom search element placements</li>
<li>Custom styles and themes using CSS</li>
<li>Promotions, set your own premium results for specific search queries</li>
<li>A new AJAX powered CSE using the Google AJAX API loader</li>
</ul>

<p><a href="http://www.web-development-blog.com/wp-content/uploads/2010/02/Google-Custom-Search.png" rel="shadowbox[post-869];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2010/02/Google-Custom-Search-300x156.png" alt="" title="Google-Custom-Search" width="300" height="156" class="alignnone size-medium wp-image-874" /></a></p>
<p>With all these new features the CSE (Custom Search Engine) becomes very attractive to use it on your own site as site search. In this tutorial we show you how-to add the custom search feature to you site using jQuery, the Thickbox plugin and the AJAX API provided by Google. To do this <strong>a result page is not necessary</strong> anymore, we show only a search box somewhere on a particular website.<span id="more-869"></span></p>
<h3>Including the Google API, jQuery and the Thickbox plugin</h3>
<p>First include the following rows to your page HEAD, you need to add them on every page where you like to show the search box.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thickbox.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thickbox.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.google.com/jsapi?key=YOURAPYKEY&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>To use the Google API you need to register an API key for your website, request a key <a href="http://code.google.com/apis/ajaxsearch/signup.html" rel="nofollow">here</a>.</p>
<h3>HTML code for the search box</h3>
<p>Below the simple HTML code for the search form and the container for the results. Place both somewhere on your webpage.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchcont&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;query_input&quot;</span>&gt;</span>Search Query: <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;query_input&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ok&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchbtn&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;resultcont&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;title&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;visibility:hidden;&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Close<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;results&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h3>jQuery code snippet</h3>
<p>The following JS code will load the Google API and if the user has clicked the search button the <a href="http://code.google.com/apis/ajaxsearch/documentation/customsearch/index.html#_class_CSC" rel="nofollow">customSearchControl</a> is initiated, the Thickbox is called, the title inside the Thickbox becomes visible, the result element is prepared and at last the input element value is executed for the search query. Add this code in your page&#8217;s HEAD surrounded by some script tags.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'search'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<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;">&quot;#searchbtn&quot;</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> customSearchControl <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">search</span>.<span style="color: #660066;">CustomSearchControl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'UNIQUE_CSE_ID'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tb_show<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;#TB_inline?height=480&amp;width=800&amp;inlineId=resultcont&amp;modal=true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;visible&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
		<span style="color: #003366; font-weight: bold;">var</span> drawOptions <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">search</span>.<span style="color: #660066;">DrawOptions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		customSearchControl.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;results&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> drawOptions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		customSearchControl.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;query_input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#title a&quot;</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>
		tb_remove<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#results&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The other click event is used to hide the Thickbox, the event will hide the title and hides also the results. The last action is needed because we show an inline element, if we don&#8217;t hide the content the results are still visible after the Thickbox is closed.</p>
<p>That&#8217;s all, simple or not? The code above needs of course some styling. I used a slightly modified version for my network site search on this blog. If you search for &#8220;wordpress&#8221; you see the &#8220;promotion&#8221; feature I mentioned above.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
<li><a href="http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/" rel="bookmark" title="February 25, 2010">Your e-mail address hidden with jQuery?</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
</ul>
<p><!-- Similar Posts took 3.155 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/google-custom-search-in-a-lightbox/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How-to choose a WordPress Hosting Provider</title>
		<link>http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/</link>
		<comments>http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 20:58:02 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[webfaction]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=856</guid>
		<description><![CDATA[If you’re using the popular blog tool WordPress, you’re probably looking for th best possible Wordpress hosting provider. Choosing a host might be hard becaise the are a lot of them. I advise you to take your time and make sure you’re choosing the best option. WordPress doesn&#8217;t require a lot of “special” server features, [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p><img class="alignleft size-full wp-image-859" title="wordpress hosting" src="http://www.web-development-blog.com/wp-content/uploads/2010/01/wordpress-hosting-e1264366350314.png" alt="" width="100" height="101" />If you’re using the popular blog tool <a rel="nofollow" href="http://wordpress.org/">WordPress</a>, you’re probably looking for th best possible Wordpress hosting provider. Choosing a host might be hard becaise the are a lot of them. I advise you to take your time and make sure you’re choosing the best option. WordPress doesn&#8217;t require a lot of “special” server features, one reason more why most hosting provider will offer to host your blog. You don&#8217;t need one at the top-of-the-line and don&#8217;t go for the cheapest plan you can find.</p>
<p>For the beginning blog a shared hosting plan should be enough, be sure an account upgrade is possible at any time. This is because you never know how fast your site is going to grow or how big it is going to get, and it’s always better to be well prepared. Check also the possibilities to move your account from a shared hosting plan to a VPS or dedicated server. You also want to avoid the smaller, lesser-known hosts. Go for the companies where a lot of people talk about, don&#8217;t host by some new company from a guy you met on forum for example.</p>
<blockquote><p>Don&#8217;t forget, if you blog has frequent reader and traffic a hosting failure can ruin your blog site.</p></blockquote>
<h3>User and file permissions</h3>
<p>Wordpress has great features to maintain the core system, any plugins and your <a href="http://www.all4yourwebsite.com/wordpress_themes.php">Wordpress themes</a>. While for the download and update from external files an build-in FTP function act as a kind of fall-back feature, you need the ability to edit your files right on the server. The last one requires some permissions to edit files thought the Wordpress backend. <span id="more-856"></span>A normal webserver is configured that files have a 0644 permission and directories have a 0755 permission. Most PHP/Apache powered webserver using one user ID to process the PHP files. This permission is okay for most PHP functions but not for file based functions used to edit template or plugin files. A few hosting provider offer services where PHP scripts are executed with user ID from the web hosting account. Providing hosting accounts this way is more secure than raising the values for the file/directory permissions to 666/777. If the PHP scripts are executed by the host account user Wordpress doesn&#8217;t need the FTP fallback feature and all updates and downloads are served much faster. The file upload tool from Wordpress back-end works without any problems if PHP scripts are executed with user permissions.</p>
<h3>Important features you need</h3>
<ul>
<li>Your host has to provide daily backups, ask them how long each backup is stored (several days are a must to have feature, more than a week is nice)</li>
<li>Host your blog in the country where you except to have the most visitors. This way most of your visitors will see your site very fast.</li>
<li>Check if the database and mail service is not hosted on the same machine as the website service. Most of the the mail server can slow down a server if mail related service have to fight back a lot of spam.</li>
</ul>
<h3>More PHP related requirements</h3>
<p>These features are not required by the Wordpress core system but many plugins: cURL, safe_mode=off, simpleXML, Socket support</p>
<h3>WebFaction, smarter web hosting</h3>
<p>Now that you know what to look for in a host, it shouldn’t be too hard to make a decision. If you’d like to go the fast way and skip researching, I recommend <a rel="nofollow" href="http://bit.ly/3z4QHw">webfaction.com</a> hosting, we use it for this blog site. <a rel="nofollow" href="http://bit.ly/3z4QHw">WebFaction</a> fits all of the discussed requirements, and it’s very affordable overall. It’s literally perfect for hosting WordPress sites, and if you know for a fact you are going to be a webmaster for a while, you can save a significant amount of money by pre-paying for 2-5 years. WebFaction has hosting plans ranging from 10GB to 60GB, and from $5.50 to $34.50 per month. There’s a great selection, so you can find a plan that’s perfect for your budget and your wallet.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/create-custom-website-backups-using-cron/" rel="bookmark" title="October 17, 2009">Create custom website backups using CRON</a></li>
<li><a href="http://www.web-development-blog.com/archives/website-monitoring-services-reviews-and-facts/" rel="bookmark" title="December 13, 2009">Website Monitoring Services: Reviews and Facts</a></li>
<li><a href="http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/" rel="bookmark" title="September 1, 2009">Sending e-mails via SMTP with PHPmailer and Gmail</a></li>
</ul>
<p><!-- Similar Posts took 3.254 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery Contact form for your website</title>
		<link>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/</link>
		<comments>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 21:32:34 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[contact form]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[phpmailer]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=839</guid>
		<description><![CDATA[These days it&#8217;s very hard to prevent your e-mail box against spam if you like to get in touch with your website&#8217;s visitors. If you place some e-mail address on your website or even a regular contact form makes you possibly a victim of spambots. There are many ways to protect your inbox against spam, [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>These days it&#8217;s very hard to prevent your e-mail box against spam if you like to get in touch with your website&#8217;s visitors. If you place some e-mail address on your website or even a regular contact form makes you possibly a victim of spambots. There are many ways to protect your inbox against spam, spam filters and protections on your contact form page will help for sure.</p>

<p>In this tutorial we show how to create a modern contact form that is linked by a simple text link and opens in a fancy <strong>Lightbox</strong> where all form handling, including reCAPTCHA validations, are processed by PHP and the jQuery Ajax function. After the form submission was successful we are using the PHP Class script PHPMailer to send the message via SMTP.</p>
<h3>Previous Tutorials we have used for this application</h3>
<p><a href="http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/">Create custom reCAPTCHA images using their API</a><br />
We use the reCAPTCHA API to create a user validation image to protect the form against spam attacks.</p>
<p><a href="http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/">Sending e-mails via SMTP with PHPmailer and Gmail</a><br />
We send e-mail messages using the <a href="http://sourceforge.net/projects/phpmailer/" rel="nofollow">PHPmailer</a> script via SMTP, the mail function from this previous tutorial is the base for this tutorial as well.<span id="more-839"></span></p>
<p>Next we use the Ajax function from <a href="http://docs.jquery.com/Downloading_jQuery" rel="nofollow">jQuery</a> to send the form variables to our PHP e-mail script. This tutorial describes how-to to use all the functions in one application, please check the other tutorials if you need more information. We will not explain the code for PHPMailer and reCAPTCHA in this tutorial. You need an API key for the <a href="http://recaptcha.net/whyrecaptcha.html" rel="nofollow">reCAPTCHA</a> service.</p>
<h3>Thickbox jQuery Plugin</h3>
<p>We use the <a href="http://jquery.com/demo/thickbox/" rel="nofollow">Thickbox plugin</a> for this tutorial because we think that this plugin is easy to use and very flexible. If you visit the Thickbox website you will notice some &#8220;warning&#8221; from the developer, he says that he doesn&#8217;t continue the development. If you don&#8217;t like to use the Thickbox plugin you need to use one of the other Lightbox plugins available on the Internet. Since the application is not related to the Thickbox plugin, it should be easy to use that code with most other Lightbox scripts as well.</p>
<h3>Contact form</h3>
<p>This page is used to collect the users input, will validate the input on the client side and will post the data to the PHP e-mail script. Create a file with this code and call it <strong>contact-form.html</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Contact form<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://api.recaptcha.net/js/recaptcha_ajax.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span></pre></div></div>

<p>Next we have the jQuery script block for the form validations, Ajax form submission and the code to request the challenge image from the reCAPTCHA API.</p>
<p>After the document is loaded the reCAPTCHA images is added. If the user has clicked the button #submit_button the Ajax function is called with: </p>
<ul>
<li>Options like the PHP e-mail script, </li>
<li>the form data, </li>
<li>the data type <strong>JSON</strong>, </li>
<li>a pre-submit handler for the form field validations </li>
<li>and a success handler that put the response into the #output container.</li>
</ul>

<div class="wp_syntax"><div class="code"><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: #003366; font-weight: bold;">var</span> RecaptchaOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> theme <span style="color: #339933;">:</span> <span style="color: #3366CC;">'custom'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
 	Recaptcha.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'your public key'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'recaptcha_image'</span><span style="color: #339933;">,</span> RecaptchaOptions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	Recaptcha.<span style="color: #660066;">focus_response_field</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#submit_button'</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: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'email.php'</span><span style="color: #339933;">,</span>
			data<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form#myform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
			beforeSend<span style="color: #339933;">:</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> resp_field <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#recaptcha_response_field'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#name'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#email'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> message <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#message'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>resp_field<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #000066;">name</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>email<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>message<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#output'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'All fields are required'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
				<span style="color: #009900;">&#125;</span>
				emailpat <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^([a-z0-9])+([\.a-z0-9_-])*@([a-z0-9])+(\.[a-z0-9_-]+)+$/i</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>emailpat.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>email<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#output'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'The e-mail address is not valid.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
					<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</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>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'success'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#formcont'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#output'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">errmessage</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><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></div></div>

<p>The form has just a few fields for name, e-mail address and message. Note the container with the ID <em>recaptcha_image</em>, this DIV element holds the reCAPTCHA challenge image.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Contact form<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;formcont&quot;</span>&gt;</span>				
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;myform&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;naam&quot;</span>&gt;</span>Name:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span>&gt;</span>E-mail:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span>&gt;</span>Message:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_image&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_response_field&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_response_field&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit_button&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> 
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;output&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h3>PHP e-mail script</h3>
<p>So far the client side code, now we need an email script called <strong>email.php</strong> with following functions:</p>
<ul>
<li>One that validates the submitted reCAPTCHA answer against the API,</li>
<li>has some basic validations on the server side (empty fields)</li>
<li>sends the e-mail message using the PHPmailer class,</li>
<li>and responds (echo) the message in JSON format.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHPMailer/class.phpmailer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'error'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_response_field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$answer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_response_field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'challenge'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_challenge_field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>	
		<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'response'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$answer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'remoteip'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'privatekey'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'your private key'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://api-verify.recaptcha.net/verify&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span>PHP_EOL<span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// enable SMTP</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPDebug</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// debugging: 1 = errors and messages, 2 = messages only</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPAuth</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// authentication enabled</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPSecure</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ssl'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// secure transfer enabled REQUIRED for Gmail</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtp.gmail.com'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">465</span><span style="color: #339933;">;</span> 
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'you at gmail dot com'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'your gmail password'</span><span style="color: #339933;">;</span>      
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'you@website.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Name: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> PHP_EOL <span style="color: #339933;">.</span> 
				<span style="color: #0000ff;">'E-mail: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> PHP_EOL <span style="color: #339933;">.</span> PHP_EOL <span style="color: #339933;">.</span> 
				<span style="color: #0000ff;">'Message:'</span> <span style="color: #339933;">.</span> PHP_EOL <span style="color: #339933;">.</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Some message from your site'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Igetthe@mail.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Mail error: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ErrorInfo</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'success'</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;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Message submitted succesfully!'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</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: #0000ff;">'incorrect-captcha-sol'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'The entered text from the Captcha image is wrong.'</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;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Can\'t validate the Captcha image.'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$resp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'errmessage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Missing required fields!'</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: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>How-to use it on your website?</h3>
<p>if you have finished both files you can use them on your site, upload the two created files, the jQuery library, the Thickbox plugin files and the PHPmailer class (if you don&#8217;t have those files on your server). Double check all the paths and add the jQuery library and the Thickbox plugin files to the page header from that page, where you like to place one or more <strong>Contact</strong> links:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery-1.3.2.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thickbox.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thickbox.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>You don&#8217;t need to add more jQuery code because the code is already included in the Thickbox plugin file. Use the following code for each link:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contact-form.html?TB_iframe=true&amp;height=480&amp;width=640&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thickbox&quot;</span>&gt;</span>Contact<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>That&#8217;s all, if you have any questions please post them below. At the moment there is no demo but you can download the <a href="http://www.finalwebsites.com/forums/topic/jquery-contact-form-for-your-website-tutorial-code">example code</a> here.</p>

<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/" rel="bookmark" title="November 2, 2009">jQuery form plugin and PHP file uploads</a></li>
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
<li><a href="http://www.web-development-blog.com/archives/integrate-your-mailchimp-newsletter-subscription/" rel="bookmark" title="October 26, 2009">Integrate your MailChimp Newsletter Subscription</a></li>
</ul>
<p><!-- Similar Posts took 3.463 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ajax requests using jQuery and PHP</title>
		<link>http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/</link>
		<comments>http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 06:17:52 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=797</guid>
		<description><![CDATA[Our last tutorial about the flickr API was an example on how-to search the flickr photo database for images using some short PHP code. This time we will use parts from the past tutorial together with some jQuery Ajax requests to show our photo search result without reloading the web page.

jQuery&#8217;s Ajax implementation
One of the [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>Our last tutorial about the <a href="http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/">flickr API</a> was an example on how-to search the flickr photo database for images using some short PHP code. This time we will use parts from the past tutorial together with some jQuery Ajax requests to show our photo search result without reloading the web page.</p>

<h3>jQuery&#8217;s Ajax implementation</h3>
<p>One of the most powerful jQuery functions is the Ajax function. The function provides enough options to make your XMLHttpRequest flexible enough to define;</p>
<ul>
<li>what type of response you need like to handle in your Ajax application (XML, JSON, HTML, script or text)</li>
<li>an option about what the script need to do before the request is send (validations, set a pre-loading image, etc.)</li>
<li>What to do after the request and response are successful</li>
<li>and options like the request URL (f.e. your PHP script), the time-out value and more. Check the <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="nofollow">jQuery page</a> for all available options.</li>
</ul>
<p><span id="more-797"></span></p>
<h3>The Ajax powered flickr image search</h3>
<p>In this tutorial we will create a PHP script that will search the flickr database for posted values using the flickr API. On the client site we will use some simple HTML search form and some easy to understand jQuery Ajax code to handle the requests. If you like to test this tutorial code your should try our <a href="http://www.finalwebsites.com/demos/jquery-flickr-search/">flickr Ajax search</a> demo.</p>
<h3>HTML search form</h3>
<p>For this tutorial we create a simple form with only one search field and a button. Below the form we have a DIV container with ID <strong>result</strong> as placeholder for the images. Inside the header we need to include the latest jQuery library, download a copy from the <a href="http://code.google.com/p/jqueryjs/downloads/list" rel="nofollow">jQuery website</a> if you haven&#8217;t done yet.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>Enter keyword<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;searchBtn&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Search&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>					
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;result&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<h3>jQuery Ajax functions</h3>
<p>We use a click event to process the search if the user had clicked the forms button. Before we post the request to our PHP file <strong>getFlickr.php</strong>, we perform a test for the search field. If there is no search string we return to the document with an error message. Otherwise we send the posted value to our script for further processing. If the response is successful, we pass the data to our target container with the ID <strong>result</strong>.</p>


<div class="wp_syntax"><div class="code"><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;">'#searchBtn'</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> searchVal <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#search'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'getFlickr.php'</span><span style="color: #339933;">,</span>
			data<span style="color: #339933;">:</span> <span style="color: #3366CC;">'search='</span> <span style="color: #339933;">+</span> searchVal<span style="color: #339933;">,</span>
			dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span>
			beforeSend<span style="color: #339933;">:</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;">'#result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img src=&quot;loading.gif&quot; alt=&quot;loading...&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>searchVal<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;Please enter a keyword as search value.&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   	
					<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> 	
			<span style="color: #009900;">&#125;</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>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				tb_init<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.thickbox'</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><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></div></div>

<h3>PHP code for the flickr API</h3>
<p>the following PHP snippet is based on the flickr API tutorial from the last. If you need information about the API methods, please check the previous tutorial.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Flickr <span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$apiKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR_API_KEY'</span><span style="color: #339933;">;</span> 
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://flickr.com/services/rest/?method=flickr.photos.search&amp;api_key='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apiKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;text='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;per_page=12&amp;format=php_serial'</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'search'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$Flickr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Flickr<span style="color: #339933;">;</span> 
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$Flickr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #009900;">&#40;</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;">'search'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photos'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;p&gt;Total '</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photos'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'total'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' photo(s) for this keyword.&lt;/p&gt;'</span><span style="color: #339933;">;</span>	
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photos'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">'
			&lt;img src=&quot;http://farm'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;farm&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.static.flickr.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;server&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;secret&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_s.jpg&quot; alt=&quot;&quot; /&gt;'</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;p&gt;There are no photos for this keyword.&lt;/p&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In this script we accept only the <del datetime="2009-12-29T06:29:02+00:00">POST</del> GET values from the HTML form we have created. If the <del datetime="2009-12-29T06:29:02+00:00">post</del> GET var is empty we stop the script and shoot some default error, because the field validation was already done on the client side. Next we query the flickr API for the search value and if we have a positive result (getting some photos) we use a <strong>foreach</strong> loop to create the HTML code for the thumbnails (note the _s at the end of the image file name)  At the end we echo the response in HTML format. Save this script under the <strong>getFlickr.php</strong></p>
<p>If everything works fine and your search has returned some photos, you script should looks like this:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/jQuery-flickr-image-search.png" rel="shadowbox[post-797];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/jQuery-flickr-image-search-300x131.png" alt="" title="jQuery-flickr-image-search" width="300" height="131" class="aligncenter size-medium wp-image-820" /></a></p>
<p>If you need more control on how your form and result should work, check the jQuery documentation. Maybe you like to use more animation effects for the results.<br />
<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/" rel="bookmark" title="December 7, 2009">Create custom reCAPTCHA images using their API</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/" rel="bookmark" title="November 2, 2009">jQuery form plugin and PHP file uploads</a></li>
</ul>
<p><!-- Similar Posts took 3.219 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Search for photos using PHP and the flickr API</title>
		<link>http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/</link>
		<comments>http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 22:25:33 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[photo]]></category>
		<category><![CDATA[php class]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=760</guid>
		<description><![CDATA[This PHP tutorial will show how to create a simple PHP class to search the flickr site for some photos. To get the data we use the flickr API to run a simple search and return the results in a serialized array. 
We will be using the php function &#34;file_get_contents&#34; to receive data from flickr. [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>This PHP tutorial will show how to create a simple PHP class to search the flickr site for some photos. To get the data we use the flickr API to run a simple search and return the results in a serialized array. </p>
<p>We will be using the php function &quot;file_get_contents&quot; to receive data from flickr. The data which we will receive will be a serialized PHP array which means all we need to do is unserialize the array and we will easily be able to use the data returned. As an alternative we can use a cURL function to get the data, for example if the function &quot;file_get_contents&quot; is not allowed on your web host.</p>

<h3>API Authentication</h3>
<p>The API methods we use in this tutorial doesn&#8217;t require any authentication, but we need to use an API key. Get your API key on the <a href="http://www.flickr.com/services/apps/create/apply/" target="_blank" rel="nofollow">flickr web application site</a> (You need an Yahoo account to login).</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/1.jpg" rel="shadowbox[post-760];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/1-300x157.jpg" alt="request api key" title="request api key" width="300" height="157" class="aligncenter size-medium wp-image-762" /></a><span id="more-760"></span></p>
<p>Provide some information about your application:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/2.jpg" rel="shadowbox[post-760];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/2-300x136.jpg" alt="API application" title="API application" width="300" height="136" class="aligncenter size-medium wp-image-763" /></a></p>
<p>and obtain your personal flickr API key and secret (We need only the key in this tutorial)</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/3.jpg" rel="shadowbox[post-760];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/3-300x107.jpg" alt="api key and secret" title="api key and secret" width="300" height="107" class="aligncenter size-medium wp-image-764" /></a></p>
<h3>Flickr PHP Class</h3>
<p>First we create the class structure for our class, we define a private variable for the &quot;API key&quot;, a class constructor and the function that will search later for the images.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Flickr <span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$apiKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR API KEY HERE'</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The API method we will be using is &quot;flickr.photos.search&quot;, which has a number of possible parameters. We are able to search by tags, full text, tell the API which user to search for, the minimum date it a photo was uploaded and many more. You can find a list of the parameters in the <a href="http://www.flickr.com/services/api/flickr.photos.search.html" target="_blank" rel="nofollow">flickr documentation</a>.</p>
<p>So we&#8217;re going to run a full text search and limit the number of results to 50.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://flickr.com/services/rest/?method=flickr.photos.search&amp;api_key='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apiKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;text='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;per_page=50&amp;format=php_serial'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice at the end of $search we have &quot;format=php_serial&quot; other available response formats are rest, xml-rpc, soap and json.</p>

<p>The data which will be stored in the variable $result is a serialized array, so simply unserialize it and return the data. Find below the complete class code and store the code in a file named &quot;flickr.php&quot;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Flickr <span style="color: #009900;">&#123;</span> 
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$apiKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'YOUR API KEY HERE'</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> search<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://flickr.com/services/rest/?method=flickr.photos.search&amp;api_key='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">apiKey</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;text='</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;per_page=50&amp;format=php_serial'</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>How-to use our PHP class</h2>
<p>Create a new PHP script file and add this code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'flickr.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$Flickr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Flickr<span style="color: #339933;">;</span> 
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$Flickr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">search</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'design inspiration'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photos'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'photo'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #666666; font-style: italic;">// the image URL becomes somthing like </span>
	<span style="color: #666666; font-style: italic;">// http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg  </span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;img src=&quot;http://farm'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;farm&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.static.flickr.com/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;server&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$photo</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;secret&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.jpg&quot;&gt;'</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This file simply includes the flickr class we wrote, creates a new instance of the class, runs a search for &quot;design inspiration&quot; and finally loops through the returned data and sends the output to the browser.</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/4.jpg" rel="shadowbox[post-760];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/4-300x160.jpg" alt="photo result" title="photo result" width="300" height="160" class="aligncenter size-medium wp-image-765" /></a> <strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
<li><a href="http://www.web-development-blog.com/archives/first-steps-within-the-zend-framework/" rel="bookmark" title="November 16, 2007">First steps within the Zend Framework</a></li>
<li><a href="http://www.web-development-blog.com/archives/create-custom-backups-from-your-website-using-curl/" rel="bookmark" title="July 30, 2008">Create custom backups from your website using cURL</a></li>
</ul>
<p><!-- Similar Posts took 3.433 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Website Monitoring Services: Reviews and Facts</title>
		<link>http://www.web-development-blog.com/archives/website-monitoring-services-reviews-and-facts/</link>
		<comments>http://www.web-development-blog.com/archives/website-monitoring-services-reviews-and-facts/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 21:42:52 +0000</pubDate>
		<dc:creator>finalwebsites.com</dc:creator>
				<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[locations]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[website monitoring]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=744</guid>
		<description><![CDATA[There are so many possibilities why a website went off-line, all of them have one in common: Your visitors can&#8217;t access your site and maybe they will never come back!
Possible problems why a website might be off-line:

Web server or network is down &#8211; A very common problem, there is so much computer technology used&#8230;
Some web [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>There are so many possibilities why a website went off-line, all of them have one in common: Your visitors can&#8217;t access your site and maybe they will never come back!</p>
<h3>Possible problems why a website might be off-line:</h3>
<ul>
<li>Web server or network is down &#8211; A very common problem, there is so much computer technology used&#8230;</li>
<li>Some web service has stopped working &#8211; It might be just one of them; MySQL, Apache or Named/Bind and your website doesn&#8217;t function for 100%</li>
<li>Too much traffic on your site &#8211; Most web servers doesn&#8217;t have the capacity for a high traffic website. 500 visitors at the same time might be enough to make your site slow or that a web server crashes.</li>
<li>External serving problems; a name server or DNS server is down &#8211; this one is nasty; if your DNS zone is down, it&#8217;s possible that you see the problem a day later, while others see your site down since hours.</li>
<li>A script stopped working properly &#8211; If a script is written and tested everything looks fine, but what if you get some external content via RSS or by user input? Sometimes a simple, but not standard, text character can break your website.</li>
<li>At last but not least &#8220;the hacker&#8221; &#8211; there are so many people on the web trying to bring a website down.</li>
</ul>
<p>Even if you try to do anything to protect your website or application against all the trouble above, you&#8217;re not safe for a failure. You have to monitor your website and hopefully a problem is notified fast enough before you loose a lot of visitors.<span id="more-744"></span></p>

<p>Some of you will say:</p>
<blockquote><p>&#8220;I don&#8217;t need to pay for a service, because my hosting provider is doing this for free!&#8221;</p></blockquote>
<p>That&#8217;s right many good providers will monitor the server you&#8217;re hosting on and/or they provide tools which will monitor your server or website. If you use them, check if these tests are done by a server outside from the network where your website or server is hosted. If there is a problem in the rack or router where the monitoring server and your website is located, you will never get a message about the down-time.</p>
<p>Some other important feature for international websites, is the ability to do test from different locations around the world. A problem might exist for only people from some continent, if your business has to take care about this, you should know about problems happen far away from your websites location.</p>
<p>Website monitoring is not a protection against failures but the following features will help you to &#8220;tackle&#8221; problems very fast:</p>
<ul>
<li>Monitor from different locations &#8211; if one fails the bot has to use the next one</li>
<li>Multiple notification options &#8211; SMS/text messages and email are required, if you can send a downtime message to more than one person, do this!</li>
<li>Tests for specific content &#8211; Just a ping or HTTP header is often not enough, test for specific text on your site</li>
<li>Adjustable values for a timeout &#8211; Some websites need more time than others to get loaded.</li>
</ul>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2009/12/ScreenSite24x7.png" rel="shadowbox[post-744];player=img;"><img title="ScreenSite24x7" src="http://www.web-development-blog.com/wp-content/uploads/2009/12/ScreenSite24x7-e1261464123885-300x183.png" alt="" width="300" height="183" /></a></p>
<p><em>(Screenshot response times Site24&#215;7)</em></p>
<p>If your website and server is working fine, the number of downtime messages should be very low. If you need to spend several dollars a month for SMS/text messages, it might be usefull to spend this money for better hosting. Website monitoring is to get warned if something went wrong.</p>
<h3>Website Monitoring Service Provider</h3>
<p>In this article we review three <a href="http://www.web-development-blog.com/archives/is-your-website-is-down-know-before-your-visitors-do/">website monitoring service</a> provider, all of them offer a great service product and you find them in a lower price segment. That will say, these services are acceptable for most of the websites on the Internet.</p>

<p><a rel="nofollow" href="http://site24x7.com/signup-plans.html?q=wgCjwuCY"><img class="alignnone size-full wp-image-749" title="site24x7" src="http://www.web-development-blog.com/wp-content/uploads/2009/12/site24x7.gif" alt="site24x7" width="119" height="39" /></a></p>
<p>I used Site24&#215;7 since they started offering services a few years ago. They offer anything you need to monitor your server or website; Tests on websites or server ports (you can monitor every server port) are only a view options. Visit their website for all the features they offer. They offer a free account and  15day trials for their paid services, if you use the standard or premium service you pay for each single test period  and location. If you need multiple test locations, you should use the premium plan because this plan includes 6 free locations for each test. If you need more than one website tested from multiple locations, than is this provider more expansive than others.</p>
<p><a rel="nofollow" href="http://www.hyperspin.com/"><img class="alignnone size-full wp-image-750" title="hyperspin" src="http://www.web-development-blog.com/wp-content/uploads/2009/12/hyperspin.gif" alt="hyperspin" width="150" height="32" /></a></p>
<p>Hyperspin is monitoring provider who offers a lot of features and also a great reseller program. If you&#8217;re looking for a way to monetize your websites traffic, by offering your own monitoring service, you should try them. All test features are available and they have multiple locations and you can setup four of them as a global setting for all your tests. They don&#8217;t charge you for using all the locations. They offer discounts if you buy more or if you pay in upfront for a whole year. I stopped using them because their control panel was several times not accessible from my laptop (using different IP addresses).</p>
<p><a rel="nofollow" href="http://www.pingdom.com/"><img class="alignnone size-full wp-image-752" title="pingdom" src="http://www.web-development-blog.com/wp-content/uploads/2009/12/pingdom.gif" alt="pingdom" width="137" height="50" /></a></p>
<p>Pingdom is the current servuice I&#8217;m using to monitor all my websites. Their control panel and website looks very modern and they offering a great plan with five tests for only $9.95/month. They offer e-mail, SMS/text message notifications and a some great integration with Twitter. Multiple test locations are included without any additional charge. I like the fast and clear interface and off course the price. I&#8217;m sure I will keep using them the next years.</p>
<p>While most of the features for these three website monitoring service providers are the same, is the pricing very different. I&#8217;m sure all three working great, just try them.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/is-your-website-is-down-know-before-your-visitors-do/" rel="bookmark" title="August 22, 2008">Is your website is down? Know before your visitors do!</a></li>
<li><a href="http://www.web-development-blog.com/archives/how-to-choose-a-wordpress-hosting-provider/" rel="bookmark" title="January 24, 2010">How-to choose a WordPress Hosting Provider</a></li>
<li><a href="http://www.web-development-blog.com/archives/tel-domain-launch-the-next-mobile-story/" rel="bookmark" title="March 28, 2009">.tel domain launch, the next mobile story</a></li>
</ul>
<p><!-- Similar Posts took 3.367 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/website-monitoring-services-reviews-and-facts/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Create custom reCAPTCHA images using their API</title>
		<link>http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/</link>
		<comments>http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 08:12:28 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[form plugin]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[recpatcha]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=715</guid>
		<description><![CDATA[If you need to spam protect your contact, comment or any other public form you should think about using a CAPTCHA image. A CAPTCHA image is an image with a random text which spam bots can&#8217;t read. The visitor need to enter that text into a form field and only if there is a match [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>If you need to spam protect your contact, comment or any other public form you should think about using a CAPTCHA image. A CAPTCHA image is an image with a random text which spam bots can&#8217;t read. The visitor need to enter that text into a form field and only if there is a match the form get processed.</p>
<p>Try a search for &#8220;CAPTCHA image&#8221; on Google and you will find a lot of scripts, some of them are powerful and some of them are not very effective. I&#8217;m using <a href="http://recaptcha.net/" rel="nofollow">reCAPTCHA</a> since several years, their challenge image is very effective and safe and if people can&#8217;t read it they can listen to an audio file.</p>
<p><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/recpatcha_red.png" alt="recpatcha_red" title="recpatcha_red" width="314" height="124" class="aligncenter size-full wp-image-718" /></p>
<p>I&#8217;m sure you have seen this image before, this is the challenge image you get with their default configuration. if you don&#8217;t like this huge RED image (like me) you need a custom theme. The good news is they offer a very powerful <a href="http://recaptcha.net/apidocs/captcha/" rel="nofollow">API system</a> for the client side and also for the server side. In this tutorial we use some jQuery code together with the reCAPTCHA ajax library to generate the challenge images. <span id="more-715"></span>The validation process is done by a PHP script that use a simple cURL function to submit the request and response to the reCAPTCHA server to test the submitted match. We use also the <a href="http://www.malsup.com/jquery/form/" rel="nofollow">jQuery form plugin</a> to process the form fields and client side validation.</p>

<p>If you like to see how it looks like check this <a href="http://www.finalwebsites.com/demos/custom-captcha-image-script/">custom CAPTCHA theme</a> demo page.</p>
<h3>reCAPTCHA client side script</h3>
<p>Before we start we need to register a domain name at the reCAPTCHA website to receive a public and private key. To create a custom challenge image the Ajax way, we need to include the external file <strong>recaptcha_ajax.js</strong> and we use the following JavaScript code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> RecaptchaOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	theme <span style="color: #339933;">:</span> <span style="color: #3366CC;">'custom'</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
Recaptcha.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'your public key'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'recaptcha_image'</span><span style="color: #339933;">,</span> RecaptchaOptions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Recaptcha.<span style="color: #660066;">focus_response_field</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There is only one option required for this custom function,  check <a href="http://recaptcha.net/apidocs/captcha/client.html#customization" rel="nofollow">this link</a> if you like to set more options.<br />
Next we need a small HTML snippet to show the challenge image:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_image&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_response_field&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaptcha_response_field&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit_button&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> 
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p>To get this working you need to create a form text field with the name and ID <strong>recaptcha_response_field</strong>, use the same ID name of the target DIV container as you used in the JavaScript function. Using both snippets in used in a HTML page will generate a neutral CAPTCHA image like:</p>
<p><img src="http://www.web-development-blog.com/wp-content/uploads/2009/12/captcha.jpg" alt="captcha" title="captcha" width="300" height="57" class="aligncenter size-full wp-image-720" /></p>
<p>The current code doesn&#8217;t process our CAPTCHA validation script. We do this using <a href="http://docs.jquery.com/Downloading_jQuery" rel="nofollow">jQuery</a> and the jQuery form plugin. In this tutorial we do not explain how the plugin works, we did that already in this <a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/">jQuery form plugin tutorial</a>. In the next JavaScript snippet we check if the text field is not empty and if there is a response we hide the form and show the response in the DIV container <strong>output</strong>.</p>

<div class="wp_syntax"><div class="code"><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: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> 
        target<span style="color: #339933;">:</span>        <span style="color: #3366CC;">'#output'</span><span style="color: #339933;">,</span>   <span style="color: #006600; font-style: italic;">// target element(s) to be updated with server response </span>
        beforeSubmit<span style="color: #339933;">:</span>  showRequest<span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// pre-submit callback </span>
        success<span style="color: #339933;">:</span>       showResponse<span style="color: #339933;">,</span>  <span style="color: #006600; font-style: italic;">// post-submit callback </span>
        url<span style="color: #339933;">:</span>       <span style="color: #3366CC;">'recaptcha.php'</span>  <span style="color: #006600; font-style: italic;">// override for form's 'action' attribute </span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> 
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</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;">ajaxSubmit</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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: #003366; font-weight: bold;">var</span> RecaptchaOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		theme <span style="color: #339933;">:</span> <span style="color: #3366CC;">'custom'</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
 	Recaptcha.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'your public key'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'recaptcha_image'</span><span style="color: #339933;">,</span> RecaptchaOptions<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: #006600; font-style: italic;">// pre-submit callback </span>
<span style="color: #003366; font-weight: bold;">function</span> showRequest<span style="color: #009900;">&#40;</span>formData<span style="color: #339933;">,</span> jqForm<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #003366; font-weight: bold;">var</span> resp_field <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=recaptcha_response_field]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fieldValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>resp_field<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You need to enter the validation string.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #006600; font-style: italic;">// post-submit callback </span>
<span style="color: #003366; font-weight: bold;">function</span> showResponse<span style="color: #009900;">&#40;</span>responseText<span style="color: #339933;">,</span> statusText<span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span> 
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>statusText <span style="color: #339933;">==</span> <span style="color: #3366CC;">'success'</span> <span style="color: #339933;">&amp;&amp;</span> responseText <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#formcont'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Error while processing your request<span style="color: #000099; font-weight: bold;">\n</span>Please try it again on a later moment.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Server side validation script</h3>
<p>Next we need to create a PHP script called <strong>recaptcha.php</strong> that will validate the entered text from our CAPTCHA image.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_response_field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$answer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_response_field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'challenge'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaptcha_challenge_field'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>	
	<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'response'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$answer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'remoteip'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$postData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'privatekey'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'your private key'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://api-verify.recaptcha.net/verify&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span>PHP_EOL<span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'true'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Success, you may proceed!'</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;">'Error, please try again.'</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// check the API documentation for detailed error reports</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this script we create a post array for the cURL function and post all the data to the reCAPTCHA API URL. Note all used variables are required, the post variable <strong>recaptcha_challenge_field</strong> is generated by the client API. The value for the challenge entry need to be encoded before we can post that value to the reCAPTCHA API. After we received the response we split the string and check if the first part is equal to true and output a success or error message which is presented in the target DIV container.</p>

<p>If you like to use this script on your own website feel free to download the script on our <a href="http://www.finalwebsites.com/forums/forum/php-class-downloads">PHP script forum</a>.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/" rel="bookmark" title="November 2, 2009">jQuery form plugin and PHP file uploads</a></li>
</ul>
<p><!-- Similar Posts took 3.564 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Adsense for WordPress &#8211; 5 Plugins reviewed</title>
		<link>http://www.web-development-blog.com/archives/adsense-for-wordpress-5-plugins-reviewed/</link>
		<comments>http://www.web-development-blog.com/archives/adsense-for-wordpress-5-plugins-reviewed/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 05:41:41 +0000</pubDate>
		<dc:creator>finalwebsites.com</dc:creator>
				<category><![CDATA[Advertising]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[ad formats]]></category>
		<category><![CDATA[adsense]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[revenue share]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=680</guid>
		<description><![CDATA[
If you try to monetize your blog with Google Adsense you might have noticed that this is not an easy job. Blog reader are very focused on reading the content and writing comments. Many readers will not visit your site since they read your blogs in a RSS reader. That will say that we need [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><div style="float: left; width: 42px; padding-right: 115px; margin: 0 10px 0 0;">
		<script type="text/javascript">
		<!--
		var dzone_url = "http://www.web-development-blog.com/archives/adsense-for-wordpress-5-plugins-reviewed/";
		var dzone_title = "Adsense for WordPress &#8211; 5 Plugins reviewed";
		var dzone_style = "2";
		var dzone_blurb = "";
		//-->
		</script>
		<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script></div>
<p>If you try to monetize your blog with Google Adsense you might have noticed that this is not an easy job. Blog reader are very focused on reading the content and writing comments. Many readers will not visit your site since they read your blogs in a RSS reader. That will say that we need a very flexible Adsense plugin to place our ads on the right place in our blogs articles. Some of you will say &#8220;I place them always on place A, B and C&#8221;, but I&#8217;m sure that this will not work all the time.</p>

<p>We need a plugin that has the following features:</p>
<ul>
<li> Single blog post placements</li>
<li> Unlimited number of ad layouts</li>
<li> Easy to integrate with each blog post using tags</li>
<li> <strong>NO revenue share with the plugin author!</strong></li>
</ul>
<p>Additionally we like to see features like:</p>
<ul>
<li> IP-based filter functions</li>
<li> Alternative ads for the IP filter</li>
<li> Using ad code from other networks than Google Adsense</li>
</ul>
<p>For this review we selected the 5 WordPress plugins because they have recent updates (active projects) and many features:<span id="more-680"></span></p>
<h3><a rel="nofollow" href="http://wordpress.org/extend/plugins/adsense-daemon/">Adsense Daemon</a></h3>
<p>This plugin supports three different Adsense layouts. All configured ads are placed on all your blog pages (single view). For each layout you have the control (7 options) where each ad will show up. The plugin has basic features and acts very static. A good plugin if you don&#8217;t need so much functions.</p>
<h3><a rel="nofollow" href="http://wordpress.org/extend/plugins/adsense-integrator/">AdSense Integrator</a></h3>
<p>If you need a more flexible plugin, you should check this Adsense plugin for WordPress. It has all the features we mentioned above and more: Default settings for automatic placement, full control about which pages have to show the automatic placed ads and a CSS margin for some better ad placement. Revenue share is enabled by default, but you can change this setting (if you don&#8217;t like to support the developer with 4% of all your ad impressions).</p>
<p>Everything seems working, except the single ad placement <img src='http://www.web-development-blog.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
With every placement the &#8220;initial&#8221; ad is placed too, maybe a recent bug? I posted this to the WordPress forum and will post the result here. Anyway a good plugin if this bug is fixed.</p>
<h3><a rel="nofollow" href="http://wordpress.org/extend/plugins/all-in-one-adsense-and-ypn/">All in One Adsense and YPN!</a></h3>
<p>Great plugin idea on how to configure your blog using Google Adsense or  YPN (Yahoo Network). While the configuration options are very comfortable is this plugin less flexible. All settings are site-wide and valid for all ad formats.</p>
<p>The plugin offers an option to use multiple ad formats, a random function will show them all. I don&#8217;t think that this really works (maybe for different colors?). There is an option to disable ads for single pages, but this will disable all ads on that single page. While this plugin looks really good, I will not use it.</p>
<h3 title="Easy AdSense Redux V2.82"><a rel="nofollow" href="http://wordpress.org/extend/plugins/easy-adsense-redux/">Easy AdSense</a></h3>
<p>If you check the WordPress plugin page you should think that this is a great plugin, but I deactivated the plugin very quickly. At the moment that the plugin was activated, it shows already the Adsense ads from the plugin author and also at least one link to his website on each of your blog pages. I need to mention that I choose the plugin because according the author, is this version more advanced and <strong>doesn&#8217;t</strong> include a revenue share. The plugin has a lot of functions to configure the different products like Adsense for search and feeds and of course the content and link units. I&#8217;m sure you can treat the setting that way to get a static ad setup for your site, but I don&#8217;t like a plugin that includes code in my site without permission and that&#8217;s the reason why my advice is to NOT using this plugin. You never know what a future version will do with your website!</p>

<h3><a rel="nofollow" href="http://wordpress.org/extend/plugins/quick-adsense/">Quick Adsense</a></h3>
<p>Finally a plugin that has all important features and works for 100%! Using this plugin you have all the options you need for your blog site: Static placements for your whole website, custom placements for your posts using simple snippets or just disable ads for a single post. This plugin has more features:</p>
<ul>
<li>Add your Adsense code to your blog posts and your sidebar widgets, all settings are controlled through a single settings page.</li>
<li>You don&#8217;t need to remember the tag names, just place them using quick tags in the HTML mode of your editor.</li>
<li>There is space for 10 different ad layouts for the blog pages and 3 in your sidebar.</li>
<li>There are no strings attached will say no revenue share or unwanted links, the only thing the author asks is to place a link or button.</li>
</ul>
<p>There is one feature missing; the IP filter with the option to show alternative ads. Since this feature is very special and should work together with a GEO location script, I think I can miss this feature for now.</p>
<p>At the end I must say I go for the Quick Adsense plugin, because I need a plugin that makes it possible to place the ads on locations I choose while writing a blog post. The Adsense Integrator is also a good plugin, but because of the bug in the current version it&#8217;s not useful for my website.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/useful-plugins-for-your-bbpress-forum/" rel="bookmark" title="August 29, 2009">Useful Plugins for your bbpress Forum</a></li>
<li><a href="http://www.web-development-blog.com/archives/adsense-for-domains-just-another-domain-parking-service/" rel="bookmark" title="February 22, 2009">AdSense for Domains, just another Domain Parking Service?</a></li>
<li><a href="http://www.web-development-blog.com/archives/a-new-wordpress-theme-for-our-blog/" rel="bookmark" title="March 15, 2009">A new Wordpress theme for our blog</a></li>
</ul>
<p><!-- Similar Posts took 3.308 ms --></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div><div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/adsense-for-wordpress-5-plugins-reviewed/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
