<?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; PHP scripts</title>
	<atom:link href="http://www.web-development-blog.com/archives/category/php-scripts/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>Wed, 25 Aug 2010 19:46:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>5 Useful jQuery Snippets for your Website</title>
		<link>http://www.web-development-blog.com/archives/5-useful-jquery-snippets-for-your-website/</link>
		<comments>http://www.web-development-blog.com/archives/5-useful-jquery-snippets-for-your-website/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 20:22:29 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1277</guid>
		<description><![CDATA[jQuery is a popular JavaScript library which is used by many developers and applications. While using jQuery you need to write less code, writing functions is less complex and there are a lot of plugins you can use for free in your web application. Even if you code everything by yourself, you need only a [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery is a popular JavaScript library which is used by many developers and applications. While using jQuery you need to write less code, writing functions is less complex and there are a lot of plugins you can use for free in your web application. Even if you code everything by yourself, you need only a few rows of code to create nice and powerful features for your website. If you&#8217;re in hurry check the <a href="http://www.web-development-blog.com/jquery-demo/">jQuery demo page</a>.</p>
<h2>Populate select menus with jQuery and Ajax</h2>
<p>One of the most powerful jQuery function is the <a rel="nofollow" href="http://api.jquery.com/category/ajax/">Ajax Suite</a>. This example shows how-to populate a second select menu based on the option from the first select menu.</p>
<p>Just in case we have this select menu with the main categories:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;category&quot;</span>&gt;</span>Choose: <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;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;category&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;category&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fruit&quot;</span>&gt;</span>Fruit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;grain&quot;</span>&gt;</span>Grains<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vegetables&quot;</span>&gt;</span>Vegetables<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</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>

<p>If someone has changed the value for this select menu, we want to show the equivalent menu inside the span element with the ID &#8220;subcat&#8221;. To do this we use this jQuery snippet that makes an Ajax request to a PHP file called &#8220;getSubCat.php&#8221;. After the select menu is changed a loading image will show up (in case of slow Internet connections), the PHP script is called and the sub-select menu becomes visible.<span id="more-1277"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#category'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</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> category <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'getSubCat.php'</span><span style="color: #339933;">,</span>
			data<span style="color: #339933;">:</span> <span style="color: #3366CC;">'cat='</span> <span style="color: #339933;">+</span> category<span style="color: #339933;">,</span>
			dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span>
			beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#subcat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img src=&quot;loader.gif&quot; alt=&quot;loading...&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
			success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#subcat'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The PHP code we are using for the file called getSubCat.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Apples'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Pears'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Cherries'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Oranges'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Kiwis'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'grain'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Wheat'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Corn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'vegetables'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tomatoes'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Beans'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Peas'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Peperoni'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// use a database instead, this array is only some simple demo data</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;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</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;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;select id=&quot;subselect&quot; name=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;option value=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
	&lt;/select&gt;
&nbsp;
'</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;">'Array-key doesn\'t exist'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Invalid request'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>This is a simple example on how you can use the Ajax function, the function has much more features which makes it a very flexible function.</p>
<h2>Disable/enable the form submit button with jQuery</h2>
<p>On pages with registration or order forms you like to treat the visitor to accept some terms of service before he/she can continue the form. A very nice function to do this is, to disable the submit button until the visitor has clicked some check box (like: Click here to accept the TOS). The following snippet will enable/disable the submit button after the check box is checked or not.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#accept'</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#buybtn'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#buybtn'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</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: #009900;">&#40;</span><span style="color: #3366CC;">'#buybtn'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Together with this function, we use the following HTML for the submit button:</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;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;accept&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;accept&quot;</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;y&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> I accept the conditions!
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;buybtn&quot;</span> <span style="color: #000066;">disabled</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit&quot;</span> <span style="color: #000066;">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;Send&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<h2>Simple photo gallery with thumbnails</h2>
<p>If you&#8217;re looking for a light-weight photo gallery function, this snippet is for you. The function works very simple: If the visitor has clicked a thumbnail the value from &#8220;href&#8221; attribute is passed to the &#8220;src&#8221; attribute from the bigger image. Thats all, check the jQuery code and of course the HTML example.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#thumbs 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>
	<span style="color: #003366; font-weight: bold;">var</span> changeSrc <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#detail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;src&quot;</span><span style="color: #339933;">,</span> changeSrc<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></pre></div></div>


<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;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;detail&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img/1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;big view&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img/1.jpg&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumbs/1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb 1&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img/2.jpg&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumbs/2.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb 2&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img/3.jpg&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumbs/3.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;thumb 3&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<h2>Show and hide HTML elements based on Radio selection</h2>
<p>jQuery has great functions which show or hide HTML elements. This example is about to show some additional list based on a selection which is made by checking a radio button. The script checks first if &#8220;the&#8221; button is checked and shows the additional container, otherwise it hides the &#8220;this&#8221; container.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#payments input[type=radio]'</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[name=payment]:checked'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;creditcard&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#cards&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#cards&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;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The HTML snippet has a radio group and a DIV container which becomes visible when the radio with the value &#8220;creditcard&#8221; is checked.</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;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;payments&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;creditcard&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;payment&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;creditcard&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> Creditcard
<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;cards&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;cctype&quot;</span>&gt;</span>Choose one: <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;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cctype&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cctype&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;master&quot;</span>&gt;</span>MasterCard<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;visa&quot;</span>&gt;</span>Visa<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;amex&quot;</span>&gt;</span>American Express<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;payment&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;paypal&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> PayPal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;payment&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wire&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> Wire/transfer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<h2>Count clicks for Google Analytics using jQuery</h2>
<p>The last snippet is an easy way to count clicks from external links within a DIV container. Without the requirement to add additional Google Analytics code to your link elements, it&#8217;s possible to count those link clicks in Google Analytics.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mylinks a[href^=&quot;http&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>
 	pageTracker._trackPageview<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/outgoing/'</span><span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This tiny function will count the links from a DIV container with the ID &#8220;mylinks&#8221; like:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://simpay.org/&quot;</span>&gt;</span>PayPal Payments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> | <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.finalwebsites.com/web_hosting_promotion.php&quot;</span>&gt;</span>Wordpress Hosting<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>You can try all these function on this <a href="http://www.web-development-blog.com/jquery-demo/">jQuery demo</a> page, a download link is available on the same page. If you have any question or suggestions, please be my guest and use the comment form below.<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.896 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/5-useful-jquery-snippets-for-your-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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[<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 4.049 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/start-a-hosting-business-with-directadmin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>404 Errors: Report, monetize and analyse</title>
		<link>http://www.web-development-blog.com/archives/404-errors-report-monetize-and-analyse/</link>
		<comments>http://www.web-development-blog.com/archives/404-errors-report-monetize-and-analyse/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 04:57:00 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[Google services]]></category>
		<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[404 error]]></category>
		<category><![CDATA[adsense]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[site search]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1136</guid>
		<description><![CDATA[After your websites getting more pages and links, the chance that a visitor will follow a dead link to your site exists. If a visitor is trying to access a page on your site, the server will report (normally) a 404 error. The response is by default some unfriendly page with some spare information about [...]]]></description>
			<content:encoded><![CDATA[<p>After your websites getting more pages and links, the chance that a visitor will follow a dead link to your site exists. If a visitor is trying to access a page on your site, the server will report (normally) a 404 error. The response is by default some unfriendly page with some spare information about the error which let most visitors stop visiting your site. But using the 404 error the right way, you the site owner can collect important information like:</p>
<ul>
<li>Of course the broken link or URL</li>
<li>The HTTP_REFERER information where the dead link is available</li>
<li>How often people try to access the bad URL</li>
</ul>
<p>Using the right tools you&#8217;re able to turn 404 errors into a powerful resource:</p>
<ul>
<li>Provide a site search feature and let people search what they are looking</li>
<li>Add advertisements to your error page and start earning money</li>
<li>Learn about what people like to see on your site</li>
</ul>
<p>In this tutorial we will show you how-to:</p>
<ul>
<li>Create a dynamic error page using the Google Site search and Adsense content ads</li>
<li>Setup Google analytics to track 404 errors using a filter</li>
<li>Set the site search feature with Google Analytics to collect the search queries from your visitor</li>
</ul>
<p><span id="more-1136"></span></p>
<h3>Error reporting page</h3>
<p>With the Apache webserver it&#8217;s possible to use custom directives for your error script, place this code into your .htaccess file (place the file into the site root):<br />
<code><br />
ErrorDocument 400 /error.php?err=400<br />
ErrorDocument 401 /error.php?err=401<br />
ErrorDocument 403 /error.php?err=403<br />
ErrorDocument 404 /error.php?err=404<br />
ErrorDocument 500 /error.php?err=500<br />
</code><br />
We use for the custom error script the most common HTTP errors.<br />
Next we need to create a PHP script called error.php which can handle the different errors:</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;">$errorNum</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$err_str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">404</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Not Found'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Bad Request'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">401</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Unauthorized'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">403</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Forbidden'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Internal Server Error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$err_str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errorNum</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;An error occured: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$err_str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errorNum</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/h1&gt;
&nbsp;
&lt;!-- place here your advertisement --&gt;
&nbsp;
&lt;!-- place here your Google analytics code --&gt;
&lt;/body&gt;
&lt;/html&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This script will show the different errors and also some advertisement if you add the ad code. Don&#8217;t forget to add the GA code snippet.</p>
<h3>Track dead links in Google Analytics</h3>
<p>In case of a 404 error the page title on this custom error page will be &#8220;Not Found&#8221;. We use the page title as a filter in Google Analytics to track the page views. Create a new profile for the site you&#8217;re working on and add this filter:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2010/06/Edit-Filter-Google-Analytics1.png" rel="shadowbox[post-1136];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2010/06/Edit-Filter-Google-Analytics1-300x178.png" alt="" title="Edit-Filter-Google-Analytics" width="300" height="178" class="alignnone size-medium wp-image-1144" /></a></p>
<h3>Adding Google Site Search to your 404 error page</h3>
<p>If you haven&#8217;t done yet, create a <a href="http://www.google.com/cse/manage/create">Google site search</a> for your website. Add only your own website to the list of searched sites and don&#8217;t search the entire web. Add your Google Adsense ID (section &#8220;Make Money&#8221;) and head to the section &#8220;Look and feel&#8221; and select the option Iframe. Choose a style for the search form / result and maybe you like to customize the style. Push now the button &#8220;Get code&#8221; (or enter the section &#8220;Get code&#8221; from the sidebar) and enter there the URL from your error page.<br />
Copy / paste the code for the search form and the results into the body section from your error page. Your completed page will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$errorNum</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'err'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$err_str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">404</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Not Found'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Bad Request'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">401</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Unauthorized'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">403</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Forbidden'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Internal Server Error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$err_str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errorNum</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;An error occured: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$err_str</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$errorNum</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/h1&gt;
&nbsp;
&lt;form action=&quot;http://www.yourdomain.com/error.php&quot; id=&quot;cse-search-box&quot;&gt;
  &lt;div&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;cx&quot; value=&quot;thisCodeIsProvidedByGoogleCSE&quot; /&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;cof&quot; value=&quot;FORID:10&quot; /&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;ie&quot; value=&quot;UTF-8&quot; /&gt;
    &lt;input type=&quot;text&quot; name=&quot;q&quot; size=&quot;31&quot; /&gt;
    &lt;input type=&quot;submit&quot; name=&quot;sa&quot; value=&quot;Zoeken&quot; /&gt;
  &lt;/div&gt;
&lt;/form&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en&quot;&gt;&lt;/script&gt;
&nbsp;
&lt;div id=&quot;cse-search-results&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
  var googleSearchIframeName = &quot;cse-search-results&quot;;
  var googleSearchFormName = &quot;cse-search-box&quot;;
  var googleSearchFrameWidth = 600;
  var googleSearchDomain = &quot;www.google.com&quot;;
  var googleSearchPath = &quot;/cse&quot;;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/afsonline/show_afs_search.js&quot;&gt;&lt;/script&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</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: #666666; font-style: italic;">// show the ad only if there is no search</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;!-- place here your advertisement --&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;!-- place here your Google analytics code --&gt;
&lt;/body&gt;
&lt;/html&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We placed the add code also into some <strong>IF</strong> clause, because there should not be another Google Adsense advertisement beside the Google ads from the result page.</p>
<h3>Enable site search tracking in Google Analytics</h3>
<p>The code for the error page is complete and we move to the last step: Tracking the site search queries from the error page. To do this we need to go in Google Analytics to the profile we created for the error page and click <strong>Edit</strong> (twice), check the setting <strong>Do Track Site Search</strong>, enter a &#8220;q&#8221; as the &#8220;Query Parameter&#8221; and click <strong>Safe Changes</strong>.</p>
<p>This error page is very basic and you need add your sites <a href="http://www.all4yourwebsite.com/website_templates.php">web template</a> to make it complete. If you like this tutorial and you have used the code on your own site please share the URL to your new or updated error page. Even if you don&#8217;t like to use the code from this page, we advice to track the errors and also the site search queries from your visitors. If you have questions or comments please post them below.<br />
<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/top-your-sales-with-google-commerce-search/" rel="bookmark" title="November 29, 2009">Top your sales with Google Commerce Search</a></li>
<li><a href="http://www.web-development-blog.com/archives/new-search-options-but-unrelated-results-in-google-blog-search/" rel="bookmark" title="October 1, 2009">New Search Options but unrelated results in Google Blog Search</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.807 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/404-errors-report-monetize-and-analyse/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Create PDF documents Online with TCPDF</title>
		<link>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/</link>
		<comments>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/#comments</comments>
		<pubDate>Thu, 27 May 2010 17:50:26 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[documents]]></category>
		<category><![CDATA[invoice]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[php class]]></category>
		<category><![CDATA[tcpdf]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1098</guid>
		<description><![CDATA[Many web applications using PDF documents for invoices, contracts and many other doc types. There are a few PHP classes which are able to create PDF documents online, one of them is TCPDF. This tutorial is about how-to use the TCPDF class while creating a simple invoice document. If you like to take a sneak [...]]]></description>
			<content:encoded><![CDATA[<p>Many web applications using PDF documents for invoices, contracts and many other doc types. There are a few PHP classes which are able to create PDF documents online, one of them is TCPDF. This tutorial is about how-to use the TCPDF class while creating a simple invoice document. If you like to take a sneak peak on the result, check this website which generates the <a href="http://www.pdffacturatie.nl/">PDF Invoice</a> document on the fly.</p>
<h3>Why TCPDF and not some other PHP class?</h3>
<p><a href="http://www.tcpdf.org/" rel="nofollow">TCPDF</a> is based on the <a href="http://fpdf.org/" rel="nofollow">FPDF</a> class, a very stable project written for PHP4. Since several years has TCPDF much more features than FPDF and is written for PHP5 (there is also a PHP4 version). The TCPDF has also some great <a href="http://www.tecnick.com/pagefiles/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html" rel="nofollow">documentation</a> and of course examples for all important PDF jobs like:<br />
WriteHTML and RTL support, Multiple columns, JavaScript and Forms, Bookmarks (Table of Content), Multicell complex alignment, Barcodes, Set PDF viewer display preferences, EPS/AI vectorial images and many <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples" rel="nofollow">more</a>.</p>
<h3>The Zend Framework has some PDF class too&#8230;</h3>
<p>Yes right, the first plan was to write this tutorial about the Zend Framework, but after writing a few rows of code I&#8217;ve noticed that the <a href="http://framework.zend.com/manual/en/zend.pdf.html" rel="nofollow">PDF Class</a> is missing some important functions, like the <strong>MultiCell</strong>, which is used to wrap multiple rows of text. It&#8217;s a <strong>required</strong> function which was suggested as the <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Pdf_Cell+-+Logan+Buesching" rel="nofollow">Zend_Pdf_Cell</a> 2 years ago and didn&#8217;t find the way to the core version until now. I like the Zend Framework a lot but<span id="more-1098"></span> not for creating PDF documents, the PDF class is much too limited. <img src='http://www.web-development-blog.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<h3>Okay let&#8217;s start the tutorial:</h3>
<p>In this tutorial we create a PDF invoice including header logo, the invoice rows, an information box and some footer row.<br />
In our code we include some PHP files, next we&#8217;ve created a small class extension to have a custom header/footer and some handy method which creates a text box.</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;">'tcpdf/config/lang/eng.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tcpdf/tcpdf.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MYPDF <span style="color: #000000; font-weight: bold;">extends</span> TCPDF <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">Header</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setJPEGQuality</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Image</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'logo.png'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">75</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'PNG'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://www.finalwebsites.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetY</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'finalwebsites.com - PHP Script Resource, PHP classes and code for web developer'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CreateTextBox<span style="color: #009900;">&#40;</span><span style="color: #000088;">$textval</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontsize</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontstyle</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$align</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'L'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetXY</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 20 = margin left</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #000088;">$fontstyle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$fontsize</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Cell</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$textval</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$align</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>

<p>The <strong>header</strong> method has only two functions, one sets the image quality and the second will place an image (including hyperlink) on a defined place (x=120, Y=10, width=75). All coordinates are measured in Millimeters and the height for the image is calculated by the script. Inside the footer method we&#8217;re using some basic TCPDF methods to define the position, the font/style and the cell with the footer text. The third method (CreateTextBox) is just a group of TCPDF functions which makes it easier to place some text box into the PDF document. Note, the constant variable <strong>PDF_FONT_NAME_MAIN</strong> is defined inside the TCPDF config file, which is located inside the <strong>config</strong> directory.</p>
<h3>The invoice header</h3>
<p>The following code will create a TCPDF object with default values, the PDF meta data gets defined (author, title, etc.), a page is added and the invoice header with information is created using our custom text box method.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// create a PDF object</span>
<span style="color: #000088;">$pdf</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MYPDF<span style="color: #009900;">&#40;</span>PDF_PAGE_ORIENTATION<span style="color: #339933;">,</span> PDF_UNIT<span style="color: #339933;">,</span> PDF_PAGE_FORMAT<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set document (meta) information</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetCreator</span><span style="color: #009900;">&#40;</span>PDF_CREATOR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetAuthor</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Olaf Lederer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF Example'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF Tutorial'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TCPDF, PDF, example, tutorial'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// add a page</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create address box</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Customer name Inc.'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">55</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mr. Tom Cat'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Street address'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">65</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zip, city name'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">70</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// invoice title / number</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invoice #201012345'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// date, order ref</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Date: '</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Order ref.: #6765765'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">105</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Invoice Rows</h3>
<p>Now we create the information about the products we like put into the PDF invoice. First we create some headers and than we use a <strong>foreach</strong> loop to output our <strong>$orders</strong> array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// list headers</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Quantity'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Product or service'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Price'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Amount'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">129</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">195</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">129</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// some example data</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.com domain registration'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">9.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'.net domain name renewal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">11.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'SSL certificate 256-Byte encryption'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">99.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$orders</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'quant'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'descr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'25GB VPS Hosting, 200GB Bandwidth'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">19.95</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$currY</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">128</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$orders</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quant'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'descr'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$amount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quant'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">*</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'price'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #000088;">$amount</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$currY</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$total</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$total</span><span style="color: #339933;">+</span><span style="color: #000088;">$amount</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Line</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">195</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After the headers and after the list of invoice items we create a line. Inside the loop, we use the variable <strong>$currY</strong> to raise the <strong>Y coordinate by 5</strong> for each new row. The row amount is calculated by PHP and also the total amount is raised inside the <strong>foreach</strong> loop.</p>
<h3>Invoice footer and information</h2>
<p>First we create a total row using the value from the variable <strong>$total</strong> we created before. After that row we have a <strong>MultiCell</strong> which can hold the payment conditions or just some other information. You can use HTML code in this cell as well, for example a link to your terms and conditions.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// output the total row</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Total'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">135</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CreateTextBox</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$'</span><span style="color: #339933;">.</span><span style="color: #990000;">number_format</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">140</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// some payment instructions or information</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setXY</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$currY</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFont</span><span style="color: #009900;">&#40;</span>PDF_FONT_NAME_MAIN<span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">MultiCell</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">175</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;em&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit&lt;/em&gt;. &lt;br /&gt;
Vestibulum sagittis venenatis urna, in pellentesque ipsum pulvinar eu. In nec &lt;a href=&quot;http://www.google.com/&quot;&gt;nulla libero&lt;/a&gt;, eu sagittis diam. Aenean egestas pharetra urna, et tristique metus egestas nec. Aliquam erat volutpat. Fusce pretium dapibus tellus.'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'L'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</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>
&nbsp;
<span style="color: #666666; font-style: italic;">//Close and output PDF document</span>
<span style="color: #000088;">$pdf</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Output</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test.pdf'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>At the end we call the output method which will safe the created PDF under the name test.pdf and sends the document to the browser.</p>
<p>This is just an example to show how easy it is to create PDF files online. Before you start your own PDF scripts, check all the <a href="http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples" rel="nofollow">TCPDF examples</a> to get an idea how-to use the different methods.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<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/how-to-create-a-password-generator-using-php/" rel="bookmark" title="November 22, 2009">How-to create a Password Generator using 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 4.159 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/create-pdf-documents-online-with-tcpdf/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>PHP Mail Scripts using SMTP transport, a guide for beginners</title>
		<link>http://www.web-development-blog.com/archives/php-mail-scripts-using-smtp-transport-a-guide-for-beginners/</link>
		<comments>http://www.web-development-blog.com/archives/php-mail-scripts-using-smtp-transport-a-guide-for-beginners/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 09:53:26 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[php classes]]></category>
		<category><![CDATA[phpmailer]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[swift mailer]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=1049</guid>
		<description><![CDATA[PHP has a very simple mail function which is used very often for basic text mail messages. What if you need to attach files or if you need to send your e-mail messages via SMTP? Than it&#8217;s time to use a more advanced script. This is because the standard mail function has only limited standard [...]]]></description>
			<content:encoded><![CDATA[<p>PHP has a very <a href="http://www.finalwebsites.com/forums/topic/php-mail-script">simple mail function</a> which is used very often for basic text mail messages. What if you need to attach files or if you need to send your e-mail messages via SMTP? Than it&#8217;s time to use a more advanced script. This is because the standard mail function has only limited standard capabilities. There are many reasons to use SMTP transport for sending e-mail messages from your web application, some of them are:</p>
<ul>
<li>Many <a href="http://www.webfaction.com/?affiliate=finalwebsites" rel="nofollow">shared hosting providers</a> doesn&#8217;t allow to use the PHP mail() function for security reasons</li>
<li>Your web application is more flexible if you use the Simple Message Transfer Protocol (SMTP). This way your e-mail function is not limited to the servers port or e-mail configuration anymore. </li>
<li>SMTP is much more powerful and secure (using SSL)</li>
</ul>
<p>In this article we will compare three of the bigger PHP projects which allow to send e-mail messages via SMTP, including attachments. <span id="more-1049"></span></p>
<ol>
<li>The Mail class included in the <strong>Zend Framework</strong> (http://framework.zend.com/)</li>
<li><strong>Swift Mailer</strong> (http://swiftmailer.org/)</li>
<li><strong>PHPMailer</strong> (http://phpmailer.worxware.com)</li>
</ol>
<p>We reviewed these three PHP classes because they&#8217;re written for PHP5 and they are updated frequently. For our review we tried the provided examples and the documentation. We&#8217;re sure that all three classes are very powerful and offer many functions for almost every type of web application. Because this review should help the beginning PHP developer, this article is sho-case for a few functions only.</p>
<h3>Our test case for this review</h3>
<p>For our example we tested all three classes to send a plain text mail message with a single image attachment, using SMTP transport with authentication. Here is the good news; as a more experienced PHP user, I was able to use the provided examples within several minutes for each of the classes.</p>
<h3>Zend Mail Class</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include_path'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.:/path2directory/ZendFramework/library/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Loader.php'</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Mail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Loader<span style="color: #339933;">::</span><span style="color: #004000;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Mail_Transport_Smtp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'auth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span> 
              <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'smtpUser'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'smtpPassword'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$transport</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail_Transport_Smtp<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp.server.com'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$at</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttachment</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path/logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$at</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'logo.png'</span><span style="color: #339933;">;</span>                                  
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBodyText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is the text inside the mail send by Zend_Mail using SMTP transport.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'you@mail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact@mailservice.us'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your friend'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mail Subject'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$transport</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I don&#8217;t like the documentation from the Zend framework, you need to check many pages to get all the required code for the snippet above. You need to create a second object to send your message via SMTP. I&#8217;m missing the information on their site about how-to test the &#8220;send&#8221; function to create use a success or error message. Using the class is not very difficult, but installing the Zend Framework might be a hard job for the beginner. This class is a great solution for people already using the Zend Framework or where the the library is provided by the hosting provider.</p>
<h3>Swift Mailer</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Swift/lib/swift_required.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$transport</span> <span style="color: #339933;">=</span> Swift_SmtpTransport<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp.server.com'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUsername</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtpUser'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPassword</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtpPassword'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mailer</span> <span style="color: #339933;">=</span> Swift_Mailer<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$transport</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> Swift_Message<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Wonderful Subject'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'you@mail.com'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your Name'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTo</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact@mailservice.us'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Your friend'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBody</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is the text of the mail send by Swift using SMTP transport.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> Swift_Attachment<span style="color: #339933;">::</span><span style="color: #004000;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path/logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$numSent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mailer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sent <span style="color: #009933; font-weight: bold;">%d</span> messages<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$numSent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The snippet looks similar to the code from the Zend mail class, but you have to create 4 different objects:</p>
<ol>
<li>An object for the SMTP transport (Swift_SmtpTransport)</li>
<li>The object that will send the message (Swift_Mailer)</li>
<li>The message object for all mail parts (Swift_Message)</li>
<li>An object for the attachment (Swift_Attachment)</li>
</ol>
<p>The configuration/installation is much easier than for the Zend Framework, just include one single file and you&#8217;re ready to use the class. If you like this OOP (Object Oriented Programming) style used in this class, this script might be for you.</p>
<h3>PHPMailer</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'PHPMailer5/class.phpmailer.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtp.server.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPAuth</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtpUser'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'smtpPassword'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SetFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'you@mail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact@mailservice.us'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your friend'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'PHPMailer Message'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This e-mail is sent through PHPMailer.'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAttachment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'path/logo.png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Mailer error: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ErrorInfo</span><span style="color: #339933;">;</span>
<span style="color: #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;">'Message has been sent.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The coding style from this example looks very different from the two others and some PHP developer would say this is not really OOP code. Right PHPMailer doesn&#8217;t have one file for each method and for the example above you need to upload only two files. I like the PHPMailer class because of all the information you get on the project&#8217;s website. </p>
<p>The three examples above should help you to make the decision which script will work the best for you. Check the links below for the documentation related to the snippets I have used in this artikel:</p>
<ul>
<li><a href="http://framework.zend.com/manual/en/zend.mail.html" rel="nofollow">http://framework.zend.com/manual/en/zend.mail.html</a></li>
<li><a href="http://swiftmailer.org/docs/introduction" rel="nofollow">http://swiftmailer.org/docs/introduction</a></li>
<li><a href="http://phpmailer.worxware.com/index.php?pg=examplebsmtp" rel="nofollow">http://phpmailer.worxware.com/index.php?pg=examplebsmtp</a></li>
</ul>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/" rel="bookmark" title="September 1, 2009">Sending e-mails via SMTP with PHPmailer and Gmail</a></li>
<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/integrate-your-mailchimp-newsletter-subscription/" rel="bookmark" title="October 26, 2009">Integrate your MailChimp Newsletter Subscription</a></li>
</ul>
<p><!-- Similar Posts took 4.036 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/php-mail-scripts-using-smtp-transport-a-guide-for-beginners/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Best methods to optimize JPEG images for websites</title>
		<link>http://www.web-development-blog.com/archives/best-methods-to-optimize-jpeg-images-for-websites/</link>
		<comments>http://www.web-development-blog.com/archives/best-methods-to-optimize-jpeg-images-for-websites/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:53:01 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[fireworks]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[photoshop]]></category>

		<guid isPermaLink="false">http://www.web-development-blog.com/?p=964</guid>
		<description><![CDATA[While Internet connections becoming faster and faster, it&#8217;s still important to keep your website as fast as possible. One of the &#8220;slow&#8221; parts of your website are the images. In this article we show several ways to down-size the JPEG images for your website. If you design your website should use some compression for your [...]]]></description>
			<content:encoded><![CDATA[<p>While Internet connections becoming faster and faster, it&#8217;s still important to keep your website as fast as possible. One of the &#8220;slow&#8221; parts of your website are the images. In this article we show several ways to down-size the JPEG images for your website. </p>
<p>If you design your website should use some compression for your photos, banners and many other web elements. You favorite image editor should have some function to down-size your images. For this article we compare 4 ways to compress our example photo (file-size 393KB):</p>
<h3>Adobe Photoshop</h3>
<p>If you use the &#8220;Save for web&#8230;&#8221; function it&#8217;s possible to create a web optimized version from your image that is small enough and has a quality which is good enough for the Internet. In our example we used the preset &#8220;High Quality&#8221; which is equal to 60% quality. The result is a smaller file with a file-size of 95KB.</p>
<h3>Adobe Fireworks</h3>
<p>Fireworks is my favorite web image editor because of the unique feature to have bitmap and vector elements in a single file. We did an export with 80% quality and the compressed version has a file-size of 85KB.<br />
<span id="more-964"></span></p>
<h3>GIMP (free Image Editor)</h3>
<p>Both Adobe products are not free and are only available for Wndows or Mac. If you need a free editor you should try Gimp, an Image editor which many functions like the other commercial products mentioned before. The editor has also a &#8220;Safe for web&#8221; function and we used and 86% quality for our export file which becomes a size of 87KB. If you use GIMP to down-size your photos from your digital camera you should check the option &#8220;Strip EXIF&#8221;, removing the photo&#8217;s meta data will make the file smaller for another ~10KB.</p>
<h3><a href="http://www.web-development-blog.com/archives/image-manipulations-with-imagemagick/">ImageMagick</a> (command line tools)</h3>
<p>The last option is a tool we used via the command line. Using the following command the file is down-sized using an 80% quality (file size after conversion is 89KB):</p>
<p><code>convert original_100.jpg -quality 80 imagemagick_80.jpg</code>  </p>
<p>Sure this method works different from the other methods but the good point is that you can use this code in your PHP scripts or just from the command line of your web server.</p>
<h3>Original image and compressed copies</h3>
<p>Check the images below and note that the quality for the compressed images (file 2-5) is very similar.</p>

<a href='http://www.web-development-blog.com/wp-content/uploads/2010/03/original_100.jpg' rel='shadowbox[album-964];player=img;' title='Original 100%'><img width="150" height="150" src="http://www.web-development-blog.com/wp-content/uploads/2010/03/original_100-150x150.jpg" class="attachment-thumbnail" alt="Original 100%" title="Original 100%" /></a>
<a href='http://www.web-development-blog.com/wp-content/uploads/2010/03/photoshop_60.jpg' rel='shadowbox[album-964];player=img;' title='Adobe Photoshop 60%'><img width="150" height="150" src="http://www.web-development-blog.com/wp-content/uploads/2010/03/photoshop_60-150x150.jpg" class="attachment-thumbnail" alt="Adobe Photoshop 60%" title="Adobe Photoshop 60%" /></a>
<a href='http://www.web-development-blog.com/wp-content/uploads/2010/03/fireworks_80.jpg' rel='shadowbox[album-964];player=img;' title='Adobe Fireworks 80%'><img width="150" height="150" src="http://www.web-development-blog.com/wp-content/uploads/2010/03/fireworks_80-150x150.jpg" class="attachment-thumbnail" alt="Adobe Fireworks 80%" title="Adobe Fireworks 80%" /></a>
<a href='http://www.web-development-blog.com/wp-content/uploads/2010/03/imagemagick_80.jpg' rel='shadowbox[album-964];player=img;' title='Imagemagick 80%'><img width="150" height="150" src="http://www.web-development-blog.com/wp-content/uploads/2010/03/imagemagick_80-150x150.jpg" class="attachment-thumbnail" alt="Imagemagick 80%" title="Imagemagick 80%" /></a>
<a href='http://www.web-development-blog.com/wp-content/uploads/2010/03/gimp_86.jpg' rel='shadowbox[album-964];player=img;' title='GIMP 86%'><img width="150" height="150" src="http://www.web-development-blog.com/wp-content/uploads/2010/03/gimp_86-150x150.jpg" class="attachment-thumbnail" alt="GIMP 86%" title="GIMP 86%" /></a>

<p>The results after compression is very similar and the file size is between 85KB (fireworks) and 95KB (Photoshop). If you&#8217;re looking to down-size another 5-10%, you should try <a href="http://developer.yahoo.com/yslow/smushit/" rel="nofollow">Smush.it</a> a free service from Yahoo. They offer a tool which is able to optimize your images for 5-10% smaller file size without to lower the grade of quality.</p>
<h3>Optimize your JPEG images with ImageMagick and PHP</h3>
<p>If you need to optimize the images for your existing website, the following code might be useful:</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;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/home/some_directory/'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the directory with your files</span>
<span style="color: #000088;">$compr</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the quality precentage</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #339933;">,</span> PATHINFO_EXTENSION<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: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(jpg|jpeg)$/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ext</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'convert %s -quality %d %s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$compr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> 
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">closedir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Just enter the path to the the directory you like to optimize safe the code as a PHP script and execute the file from the command line of browser. Note only the JPEG files are getting compressed.</p>
<p>Optimize your images top make them load faster, but be careful don&#8217;t compress them too much. <strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/image-manipulations-with-imagemagick/" rel="bookmark" title="May 5, 2009">Image manipulations with Imagemagick</a></li>
<li><a href="http://www.web-development-blog.com/archives/upload-images-for-usage-in-tinymce/" rel="bookmark" title="September 25, 2008">Upload images for usage in TinyMCE</a></li>
<li><a href="http://www.web-development-blog.com/archives/tutorial-ftp-upload-via-curl/" rel="bookmark" title="October 11, 2007">Tutorial: FTP Upload via cURL</a></li>
</ul>
<p><!-- Similar Posts took 3.931 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/best-methods-to-optimize-jpeg-images-for-websites/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Your e-mail address hidden with jQuery?</title>
		<link>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/</link>
		<comments>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 17:35:17 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[spam]]></category>

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

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

<p>Don&#8217;t forget to block that file in your robots.txt file!<span id="more-918"></span></p>
<p>Now we need a function that will load the external content into the current page using an Ajax request.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#clickme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    	$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	  		url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'glink.html'</span><span style="color: #339933;">,</span>
                        dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'json'</span><span style="color: #339933;">,</span>
	  		success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> adr <span style="color: #339933;">=</span> data.<span style="color: #660066;">ename</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'@'</span> <span style="color: #339933;">+</span> data.<span style="color: #660066;">domain</span><span style="color: #339933;">;</span>
	  			<span style="color: #003366; font-weight: bold;">var</span> newdata <span style="color: #339933;">=</span> data.<span style="color: #660066;">htmlcode</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/%%mAdr%%/g</span><span style="color: #339933;">,</span> adr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span#ajaxresp'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>newdata<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 				
	  		<span style="color: #009900;">&#125;</span>
	  	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#hideme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 	
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#ajaxresp&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

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

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

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

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

<p>If your visitor has clicked this &#8220;contact&#8221; link the following box appears:</p>
<p><a href="http://www.web-development-blog.com/wp-content/uploads/2010/02/jquery-slide-down.png" rel="shadowbox[post-918];player=img;"><img src="http://www.web-development-blog.com/wp-content/uploads/2010/02/jquery-slide-down-300x99.png" alt="" title="jquery-slide-down" width="300" height="99" class="alignnone size-medium wp-image-919" /></a></p>
<p>If you have the jQuery and CSS code in external files, it&#8217;s possible to use the function on all your pages. The best thing is that the loaded box has also room for a personal message for your visitor. It&#8217;s just a simple solution without the need of building a contact form. This was the third article of a series with solutions on how-to add the contact information to your article or website.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/5-useful-jquery-snippets-for-your-website/" rel="bookmark" title="August 23, 2010">5 Useful jQuery Snippets for your Website</a></li>
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/" rel="bookmark" title="February 15, 2010">E-mail links, protective solutions against SPAM</a></li>
</ul>
<p><!-- Similar Posts took 3.743 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>E-mail links, protective solutions against SPAM</title>
		<link>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/</link>
		<comments>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 21:14:38 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[protect]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[spam]]></category>

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

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

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

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

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

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

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

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

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

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

<p>This method is very protective against spam bots, but will not work if JavaScript is disabled in the visitors browser. On the other site this code is very flexible and easy to use.</p>
<p>You see there are many different ways to add your e-mail address to your website without to expose the it to spam bots. If you search Google you will find much more examples, some of them are safe and some of them might have a better usability. If you don&#8217;t like to show your email address you should use a <a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/">contact form</a> on your website. If you know some great and easy function to hide an e-mail address in HTML code, please post it below. <strong>If you like this article please share the link on twitter or facebook, thanks.</strong><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/" rel="bookmark" title="January 11, 2010">jQuery Contact form for your website</a></li>
<li><a href="http://www.web-development-blog.com/archives/your-e-mail-address-hidden-with-jquery/" rel="bookmark" title="February 25, 2010">Your e-mail address hidden with jQuery?</a></li>
<li><a href="http://www.web-development-blog.com/archives/paypal-payment-tools-information-and-resources/" rel="bookmark" title="July 25, 2010">PayPal Payment Tools: Information and Resources</a></li>
</ul>
<p><!-- Similar Posts took 3.853 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/e-mail-links-protective-solutions-against-spam/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>jQuery Contact form for your website</title>
		<link>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/</link>
		<comments>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 21:32:34 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[contact form]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[phpmailer]]></category>
		<category><![CDATA[thickbox]]></category>

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

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

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

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

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

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

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

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

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

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

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

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

<p>That&#8217;s all, if you have any questions please post them below. At the moment there is no demo but you can download the <a href="http://www.finalwebsites.com/forums/topic/jquery-contact-form-for-your-website-tutorial-code">example code</a> here.</p>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.web-development-blog.com/archives/jquery-form-plugin-and-php-file-uploads/" rel="bookmark" title="November 2, 2009">jQuery form plugin and PHP file uploads</a></li>
<li><a href="http://www.web-development-blog.com/archives/create-custom-recaptcha-images-using-their-api/" rel="bookmark" title="December 7, 2009">Create custom reCAPTCHA images using their API</a></li>
<li><a href="http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/" rel="bookmark" title="December 24, 2009">Ajax requests using jQuery and PHP</a></li>
</ul>
<p><!-- Similar Posts took 4.054 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-development-blog.com/archives/jquery-contact-form-for-your-website/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ajax requests using jQuery and PHP</title>
		<link>http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/</link>
		<comments>http://www.web-development-blog.com/archives/ajax-requests-using-jquery-and-php/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 06:17:52 +0000</pubDate>
		<dc:creator>Olaf</dc:creator>
				<category><![CDATA[PHP scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery Code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[photos]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[search]]></category>

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

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

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

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

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

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

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