<?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 &#187; api</title>
	<atom:link href="http://www.web-development-blog.com/archives/tag/api/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>Sun, 25 Jul 2010 14:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Start a hosting business with DirectAdmin</title>
		<link>http://www.web-development-blog.com/archives/start-a-hosting-business-with-directadmin/</link>
		<comments>http://www.web-development-blog.com/archives/start-a-hosting-business-with-directadmin/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 07:32:53 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Web Hosting]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[dedicated server]]></category>
		<category><![CDATA[directadmin]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[vps]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1172</guid>
		<description><![CDATA[There are thousands of hosting companies on the Internet and maybe this article will help you to start your own. Many companies offering web services are hosting reseller of other (bigger) companies or have partnerships with hosting companies. Maybe you have ever thought to offer hosting services by yourself, with a dedicated server or a [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>There are thousands of hosting companies on the Internet and maybe this article will help you to start your own. Many companies offering web services are hosting reseller of other (bigger) companies or have partnerships with hosting companies. Maybe you have ever thought to offer hosting services by yourself, with a dedicated server or a VPS hosting account, it&#8217;s very easy to offer hosting plans for your existing customers. The following article will show you, using a few examples, how to use a web server installed with the software DirectAdmin to create web hosting accounts using their native API system.</p>
<blockquote><p>Don&#8217;t think it&#8217;s easy to pull a new hosting company from the ground. This market is very saturated and we suggest to start offering hosting services most of all to your existing customers only.</p></blockquote>
<h3>VPS hosting versus dedicated server hosting</h3>
<p>These days it&#8217;s not necessary to have your own dedicated server, a good maintained VPS host is often much more reliable. If the VPS hosting platform is well managed, you don&#8217;t have to worry about the shared memory because the virtualization software is able to manage all the resources. Why do you need a dedicated server if a VPS is so powerful? You need your own server for special hardware configurations or if your provider doesn&#8217;t have a good VPS platform. While many VPS companies using the same machines, the risk of hardware failures is low because hardware replacements should be a peace of cake. A &#8220;special&#8221; dedicated or colocated server might be a serious risk, f.e if the motherboard replacement is not available. <strong>A VPS host is scalable and often much cheaper than a dedicated server.<br />
</strong><span id="more-1172"></span></p>
<h3>Web Server Control Panel</h3>
<p>Using a control panel, makes it easy to create or maintain all the web hosting accounts for your customers. Sure as a Linux expert you don&#8217;t need a CP, but if you core business is web development, a control panel might really help. There are many of them, most of them are commercial products, but there are also a a few open source projects which are available for free. In this blog post we suggest to use <a href="http://www.directadmin.com/" rel="nofollow">DirectAdmin</a>, because this software is easy to use, the license is not very expensive and there is also a very powerful API system.</p>
<h3>Installing DirectAdmin</h3>
<p>After you got your VPS (or dedicated server) you&#8217;re ready to install the server software. Before you start the installation process check these DirectAdmin requirements. Most important is that your Linux server is not pre-installed with software like Apache, MySQL, PHP, FTP&#8230; check this warning from the DA website:</p>
<blockquote><p>***Please do not install services such as Apache, PHP, MySQL, Ftp, Sendmail, etc., as we will do this for you.  All we need is a CLEAN install of your operating system.***<br />
We do not recommend installing DirectAdmin on an existing live production server.<br />
DirectAdmin does not convert existing data upon install. </p></blockquote>
<p>For most DirectAdmin hosts CentOS is the preferred Linux operating system. You need also a DirectAdmin license, ask your VPS hosting provider, he can offer the license for a low fee. </p>
<p><strong>DirectAdmin installation resources:</strong></p>
<ul>
<li><a href="http://www.directadmin.com/install.html" rel="nofollow">Getting Started with DirectAdmin: What kind of server do I need?</a></li>
<li><a href="http://www.directadmin.com/installguide.html" rel="nofollow">DirectAdmin Installation Guide</a></li>
</ul>
<p>The installation process is not part of this article. If you finished the installation part, you should check this <a href="http://www.web-development-blog.com/archives/how-to-setup-the-dns-and-name-server-for-a-directadmin-web-server/">DNS installation guide</a>. </p>
<h3>Creating hosting accounts</h3>
<p>After the final re-boot and your DirectAdmin server is running, you&#8217;re able to setup hosting accounts for your customers. You can create them by yourself using the DA control panel or using the DirectAdmin API within your web application. Think about the following application process:</p>
<ol>
<li>Customer has ordered a hosting accpunt from your website</li>
<li>The payment is cleared and a request is send the API system</li>
<li>Within DirectAdmin a hosting account is created</li>
<li>The customer gets the login and hosting accpunt details via e-mail</li>
</ol>
<p>How far you&#8217;re using this features of DA depends on yourself. The <a href="http://www.directadmin.com/api.html" rel="nofollow">DirectAdmin API</a> is able to manage all functions you need. This way you&#8217;re able to create your own we application, without telling your customers that a control panel is used.</p>
<h3>Access the DirectAdmin API system</h3>
<p>The API documentation is very complete and easy to use even for less experienced developers. There is also a custom PHP class to access the API via a HTTP socket, <a href="http://files.directadmin.com/services/all/httpsocket/httpsocket.php" rel="nofollow">download the code here</a>.</p>
<p>Using this PHP class is very easy, the following code is used to fetch all the user accounts from a reseller/admin account:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'httpsocket.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTTPSocket<span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'some.server.com'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2222</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_login</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/CMD_API_SHOW_USERS'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_body</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</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: #666666; font-style: italic;">// shows the result in the browser</span></pre></div></div>

<p>Next we show how-to add a new user to an existing reseller account (the package named &#8220;default&#8221; is a pre-defined hosting package):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'httpsocket.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTTPSocket<span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'some.server.com'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2222</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_login</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/CMD_API_ACCOUNT_USER'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'create'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'add'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Submit'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'abcuser'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mail@domain.com'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'passwd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'123456'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'passwd2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'123456'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'domain'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'googles.com'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'package'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'123.123.123.123'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'notify'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yes'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_body</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</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: #666666; font-style: italic;">// shows the result in the browser</span></pre></div></div>

<p>This API call is the same as creating a user from the web interface:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2010/07/create_user.png" rel="shadowbox[post-1172];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2010/07/create_user-300x146.png" alt="" title="create_user" width="300" height="146" class="alignnone size-medium wp-image-1180" /></a></p>
<p>If you check all the API functions, you will see that it&#8217;s possible to create a 100% white labeled web application. Even if you don&#8217;t have that kind of web application, it&#8217;s very easy to create hosting accounts using the web interface on your DirectAdmin web server.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/how-to-setup-the-dns-and-name-server-for-a-directadmin-web-server/" rel="bookmark" title="September 17, 2007">How-to setup the DNS and name server for a DirectAdmin web server</a></li>
<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/setting-up-an-internet-shopping-cart/" rel="bookmark" title="November 11, 2007">Setting up an Internet shopping cart</a></li>
</ul>
<p><!-- Similar Posts took 3.776 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/start-a-hosting-business-with-directadmin/feed/</wfw:commentRss>
		<slash:comments>4</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.562 ms --></p>
<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>18</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.629 ms --></p>
<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>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.862 ms --></p>
<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>Integrate your MailChimp Newsletter Subscription</title>
		<link>http://www.web-development-blog.com/archives/integrate-your-mailchimp-newsletter-subscription/</link>
		<comments>http://www.web-development-blog.com/archives/integrate-your-mailchimp-newsletter-subscription/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 08:00:11 +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[contact form]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mailchimp]]></category>
		<category><![CDATA[mailing list]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=536</guid>
		<description><![CDATA[MailChimp is a great mailing list provider with a powerful API system. This tutorial will guide you on how-to integrate the subscription process with other forms on your website.]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p>MailChimp is a great mailing list provider with a great control panel and many useful features like: campaign management, statistics, responders and complete set of List management tools. They offer also an small code snippet to place a subscription form on your website. This form powered by jQuery is good enough for most common cases, but what if you like to combine your newsletter subscription with a standard function like contact or registration form?</p>
<blockquote><p>The secret to make your list bigger is to integrate the opt-in function with often used functions like a registration or contact form. </p></blockquote>
<p>In our tutorial we showcase how-to create a contact form application which will send a message and subscribes the user to a mailing list hosted by <a href="http://eepurl.com/cHpm" rel="nofollow" target="_blank">MailChimp</a>.</p>
<h3>Preparations</h3>
<ul>
<li>If you don&#8217;t have a MailChimp account, register one at <a href="http://eepurl.com/cHpm" rel="nofollow" target="_blank">MailChimp</a>. They offer a free account for the first 500 mailing list members and for 3.000 messages a month. <strong>Sign-up now for free and get a $30 bonus if you upgrade your account after a while.</strong></li>
<li>Setup a mailing <strong>list</strong> via the MailChimp control panel and obtain the <strong>Unique list ID</strong> (via the list settings page, lower left corner).</li>
<p><span id="more-536"></span></p>
<li>Now we need an MailChimp API Key, create one from the control panel (Account -> API Keys &#038; Info)</li>
<li>As an option create a custom field (List settings -> List Fields and *|MERGE|* Tags) and name it <strong>subscription_via</strong>. Don&#8217;t change the other variables. We use this field to store the information that a subscription is done via the contact form we create.</li>
</ul>
<h3>The contact form (html)</h3>
<p>We need to have a simple contact form, with a field for name and e-mail address, a textarea for the message and a checkbox for the subscription. The following example is very basic for a better understanding. In real you might to use some Ajax/jQuery powered form (check the jQuery form plugin listed below).</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> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;process.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</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> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&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;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&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>&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;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&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>&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;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&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;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&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;">div</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;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;newsletter&quot;</span> <span style="color: #66cc66;">/</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;newsletter&quot;</span>&gt;</span>Subscribe to newsletter<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: #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>&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;Register&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;subscribe&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></pre></div></div>

<h3>Using the MailChimp API with cURL</h3>
<p>The MailChimp API has several modes on how-to communicate with the system. In this tutorial we use the simple HTTP GET/POST URL method. We request the data using cURL functions and we like to have a response  which is a JSON array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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: #000088;">$listID</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Your List'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://api.mailchimp.com/1.2/?method=listSubscribe&amp;apikey=%s&amp;id=%s&amp;email_address=%s&amp;merge_vars[OPTINIP]=%s&amp;merge_vars[MMERGE1]=webdev_tutorials&amp;output=json'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$apikey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$listID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</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: #009900;">&#41;</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: #000088;">$url</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> ID<span style="color: #0000ff;">';</span></pre></div></div>

<p>You can see that we created a string using the PHP function <strong>sprintf</strong> to add our variables. You need to use at least one <strong>merge</strong> variable, in this example we submit the users IP and a value for the custom field we created before. After the cURL request is done we get a response called $data, the JSON array.</p>
<p>This so far about the communication. Before we submit any data we need to check if the submitted email address is valid. I the email address is valid we send the message.</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: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,})&quot;</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: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$email</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>
		<span style="color: #666666; font-style: italic;">//</span>
		<span style="color: #666666; font-style: italic;">// process here the contact form data like name and message</span>
		<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'your@mail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Subject: contact form'</span><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: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example</span>
		<span style="color: #666666; font-style: italic;">//</span></pre></div></div>

<p>Note this is just an e-mail example, nothing special because how-to create a safe contact or mail form is not part of this tutorial. We posted a few resources at the end from this article. </p>
<h3>Putting all stuff together</h3>
<p>After the e-mail address is validated and the message is send we check if the checkbox was checked to send the data to the <a href="http://www.mailchimp.com/api/rtfm/" rel="nofollow">MailChimp API</a>. Here is the complete script for the file <strong>process.php</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$apikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Your API Key'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$listID</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Your List'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subscribe'</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,})&quot;</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: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$email</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>
		<span style="color: #666666; font-style: italic;">//</span>
		<span style="color: #666666; font-style: italic;">// process here the contact form data like name and message</span>
		<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'your@mail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Subject: contact form'</span><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: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// example</span>
		<span style="color: #666666; font-style: italic;">//</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;">'newsletter'</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;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://api.mailchimp.com/1.2/?method=listSubscribe&amp;apikey=%s&amp;id=%s&amp;email_address=%s&amp;merge_vars[OPTINIP]=%s&amp;merge_vars[MMERGE1]=webdev_tutorials&amp;output=json'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$apikey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$listID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</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: #009900;">&#41;</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: #000088;">$url</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;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Check now your e-mail and confirm your subsciption.'</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;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'code'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">214</span><span style="color: #339933;">:</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'You are already subscribed.'</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">// check the MailChimp API for more options</span>
					<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Unkown error...'</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">break</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We&#8217;re using the PHP function <strong>json_decode</strong> to convert the JSON array into a PHP array and <strong>echo</strong> different messages upon the result. We used the most common results:</p>
<ul>
<li>1 (not an array) = conformation mail is send</li>
<li>code 214 = the submitted email address already exists</li>
<li>By default we use a standard message</li>
</ul>
<p>Using the API this way it&#8217;s possible to have your own (translated) messages. If you like to use more different messages for different response codes, just add them into the switch statement.</p>
<h3>Additional resources</h3>
<ul>
<li><a href="http://www.finalwebsites.com/tutorials/php_ajax_contact_form.php">A (safe) contact form using Xajax and PHPmailer</a></li>
<li><a href="http://www.malsup.com/jquery/form/" rel="nofollow">jQuery plugin for forms</a></li>
</ul>
<p><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/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/your-e-mail-address-hidden-with-jquery/" rel="bookmark" title="February 25, 2010">Your e-mail address hidden with jQuery?</a></li>
</ul>
<p><!-- Similar Posts took 5.064 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/integrate-your-mailchimp-newsletter-subscription/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Impressions from the Google I/0 conference</title>
		<link>http://www.web-development-blog.com/archives/impressions-from-the-google-i0-conference/</link>
		<comments>http://www.web-development-blog.com/archives/impressions-from-the-google-i0-conference/#comments</comments>
		<pubDate>Thu, 29 May 2008 20:52:23 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[Google services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gears]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[IO2008]]></category>
		<category><![CDATA[opensocial]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/impressions-from-the-google-i0-conference/</guid>
		<description><![CDATA[or Google the Open Source Company presents their new technology! The Google I/O conference in San Francisco is the first of his kind, during two days the conference provides the attendee 90 sessions grouped by the following categories: Ajax and JavaScript APIs and Tools Maps and Geo Mobile Social Furthermore they held sessions like Code [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><p><em><strong>or Google the Open Source Company presents their new technology!</strong></em></p>
<p>The Google I/O conference in San Francisco is the first of his kind, during two days the conference provides the attendee 90 sessions grouped by the following categories:</p>
<ul>
<li><img src="http://www.web-development-blog.com/wp-content/uploads/2008/05/logo.gif" alt="Google I/0" align="right" />Ajax and JavaScript</li>
<li>APIs and Tools</li>
<li>Maps and Geo</li>
<li>Mobile</li>
<li>Social</li>
</ul>
<p>Furthermore they held sessions like Code labs, Tech Talks and the Fireside Chat. So maybe you&#8217;re looking for the &#8220;Search&#8221; category? Yes there are a few lessons about search optimization and the Ajax Search API, but most sessions are about new modern technologies like Gears and the Google App Engine.</p>
<p><img src="http://www.web-development-blog.com/wp-content/uploads/2008/05/google_io_20081.jpg" alt="Google I/O registrations" /></p>
<p>Those people who knows Google as the search engine provider and advertising company would be very surprised about the strong open source character of this conference. <span id="more-139"></span>With the vision</p>
<blockquote><p>Create a better, full featured Internet using modern technologies</p></blockquote>
<p>Google has invited any developer to use Google technologies in their own applications.</p>
<p>While listening to several sessions, I get an good idea about Gears, OpenSocial, Google APIs like Authentication API, content API&#8217;s and the Google Checkout API. Before joining this conference I accepted to learn something I can use within my next projects. OpenSocial is something I like, a kind of standard how to create your own Social Community.</p>
<p>My first impression about Gears is not so positive; the idea is really good, but it looks like a browser add-on aka Adobe flash (not the function but the idea how to provide the technology to the client). All presentations are available to the public next week on the <a href="http://code.google.com/events/io/">Google I/0 website</a>.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/google-custom-search-in-a-lightbox/" rel="bookmark" title="February 5, 2010">Google Custom Search in a Lightbox!</a></li>
<li><a href="http://www.web-development-blog.com/archives/google-guidelines-against-modern-web-development/" rel="bookmark" title="June 8, 2007">Google guidelines against modern web development?</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>
</ul>
<p><!-- Similar Posts took 3.506 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/impressions-from-the-google-i0-conference/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>First steps within the Zend Framework</title>
		<link>http://www.web-development-blog.com/archives/first-steps-within-the-zend-framework/</link>
		<comments>http://www.web-development-blog.com/archives/first-steps-within-the-zend-framework/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 16:32:55 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[yahoo]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/archives/first-steps-within-the-zend-framework/</guid>
		<description><![CDATA[Setup a quick Yahoo Search page within a few minutes! A few days ago the &#8220;old&#8221; Google web search API has stopped working for the web public. Not a big surprise after the release of the AJAX web search API. A customer of mine is using search results in his mini sites to give them [...]]]></description>
			<content:encoded><![CDATA[<!--S-ButtonZ 1.1.5 Start--><!--S-ButtonZ 1.1.5 End--><h3>Setup a quick Yahoo Search page within a few minutes!</h3>
<p>A few days ago the &#8220;old&#8221; Google web search API has stopped working for the web public. Not a big surprise after the release of the AJAX web search API. A customer of mine is using search results in his mini sites to give them a little more body. This is why I needed to look for some alternative. During the Zend PHP conference earlier this year, I got in touch with the Zend framework and learned that there is already a class to obtain results from the Yahoo search engine. The class has features to search the Yahoo API for web sites, image, news and the local search results.</p>
<h3>Installing the library</h3>
<p>I decided some time before to use the classes from the <a href="http://framework.zend.com/home" rel="nofollow">Zend framework</a> for future projects because the classes are well written in PHP5. If you like to do the same you should install the lib on a central place on your web server to get access to the framework from all your  websites. After uploading the files I added this row to .htaccess file for the website I&#8217;m working on:</p>
<p><code>php_value include_path ".:/home/mylocation_for_zend_framework/"</code></p>
<p>This way you&#8217;re able to access the classes without to think about the class paths. Of course you are free to add this include path to the php.ini file or to your apache configuration.<span id="more-122"></span></p>
<h3>Search Yahoo via the API</h3>
<p>Before you can start you need to request a Yahoo developer key. Visit this <a href="https://developer.yahoo.com/wsregapp/index.php" rel="nofollow">page</a> and get one for free.</p>
<p>The <a href="http://framework.zend.com/manual/en/zend.service.yahoo.html#zend.service.yahoo.websearch" rel="nofollow">manual</a> for the  Zend framework has easy to use examples for all important methods. This way you&#8217;re able to have a result without to think about the code. Just create a file and add this code and add the Yahoo developer key:</p>
<p><code>require_once 'Zend/Service/Yahoo.php';<br />
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");<br />
$results = $yahoo-&gt;webSearch('PHP');<br />
foreach ($results as $result) {<br />
echo $result-&gt;Title;<br />
}</code></p>
<p>Run this script and you get the titles for the top10 results for a Yahoo search on &#8220;PHP&#8221;. Just enter a different search keyword (or variable) to get different results. According the <a href="http://developer.yahoo.com/search/web/V1/webSearch.html" rel="nofollow">Yahoo web search documentation</a> we have some important search features like:</p>
<ul>
<li>region (Yahoo has different local search engines for countries like UK, NL or DE)</li>
<li>results (the number of results you get back for your query: default 10, max. 100)</li>
<li>start (you need this one to get result pages like with a real search engine)</li>
<li>language (if you need other results than in English language)</li>
</ul>
<p>There are more options check their site for more further reference. In our example we want to have control about the options above. To use them we need to add the keys and values into an array:</p>
<p><code>$options = array('start' =&gt; 10, 'language' =&gt; 'nl', 'results'  =&gt; 10, 'region' =&gt; 'nl');</code></p>
<p>This option array can be used in the &#8220;webSearch()&#8221; method this way:</p>
<p><code>$results = $yahoo-&gt;webSearch('PHP scripts', $options);</code></p>
<p>While executing this modified snippet we get some error because the option &#8220;region&#8221; is not included in the class. Not so bad, but it&#8217;s very important to have this option because the US version doesn&#8217;t have so much Dutch language results. After checking the class (file: Zend/Service/Yahoo.php)  I found this code on row 529:</p>
<p><code>$validOptions = array('appid', 'query', 'results', 'start', 'language', 'type', 'format', 'adult_ok',<br />
'similar_ok', 'country', 'site', 'subscription', 'license');</code></p>
<p>Just add the value &#8220;region&#8221; to this array and you&#8217;re fine (I will submit this change to Zend and I&#8217;m sure they will add this change to future releases).</p>
<p>If you combine this snipped with a form you have almost a full featured search box for your website. To create a complete result with summary and URL we need this code snippet (replace this code with the prev. &#8220;output&#8221; code):</p>
<p><code>echo '&lt;p&gt;&lt;a href="'.$result-&gt;Url.'"&gt;'.$result-&gt;Title.'&lt;/a&gt;&lt;br /&gt;<br />
'.$result-&gt;Summary.'&lt;/p&gt;';</code></p>
<p>Thats all, only some small snippet and you have some fast Yahoo search results for your website.<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/php-mail-scripts-using-smtp-transport-a-guide-for-beginners/" rel="bookmark" title="April 12, 2010">PHP Mail Scripts using SMTP transport, a guide for beginners</a></li>
<li><a href="http://www.web-development-blog.com/archives/search-for-photos-using-php-and-the-flickr-api/" rel="bookmark" title="December 19, 2009">Search for photos using PHP and the flickr API</a></li>
<li><a href="http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/" rel="bookmark" title="May 27, 2010">Create PDF documents Online with TCPDF</a></li>
</ul>
<p><!-- Similar Posts took 3.674 ms --></p>
<div style="clear:both;">&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/first-steps-within-the-zend-framework/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->