<?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>TutToaster &#187; Tutorials</title>
	<atom:link href="http://www.tuttoaster.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tuttoaster.com</link>
	<description>Free Web and Graphic Design tutorials</description>
	<lastBuildDate>Thu, 21 Apr 2011 13:06:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>40 Great PhotoShop User Interface Tutorials</title>
		<link>http://www.tuttoaster.com/40-great-photoshop-user-interface-tutorials/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=40-great-photoshop-user-interface-tutorials</link>
		<comments>http://www.tuttoaster.com/40-great-photoshop-user-interface-tutorials/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 16:10:48 +0000</pubDate>
		<dc:creator>Swat Chap</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[psd]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=8184</guid>
		<description><![CDATA[Every website needs to be designed which are called web layouts. And one of the leading tools available and possibly for many more years to come is photoshop. Photoshop has become a favorite among designers for various reasons. In this collection, we look at 50 of the best web layout tutorial around the web. The [...]]]></description>
			<content:encoded><![CDATA[<p>Every website needs to be designed which are called web layouts. And one of the leading tools available and possibly for many more years to come is photoshop.</p>
<p>Photoshop has become a favorite among designers for various reasons. In this collection, we look at 50 of the best web layout tutorial around the web. The collection contains tips, and tricks that can be handy for both beginers or advanced.</p>
<h2>how to design an elegant website layout in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-design-an-elegant-website-in-photoshop.html"><img class="alignnone size-full wp-image-8185" title="how to design an elegant website layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/1.jpg" alt="how to design an elegant website layout in Photoshop" width="580" height="300" /></a><span id="more-8184"></span></p>
<h2>Software Layout #4</h2>
<p><a href="http://www.hv-designs.co.uk/2009/07/21/software-layout-4/"><img class="alignnone size-full wp-image-8194" title="Software Layout #4" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/4.gif" alt="Software Layout #4" width="580" height="300" /></a></p>
<h2>Photoshop a Paper Texture from Scratch then Create a Grungy Web Design with it!</h2>
<p><a href="http://psd.tutsplus.com/tutorials/interface-tutorials/photoshop-paper-texture-from-scratch-then-create-a-grungy-web-design-with-it/"><img class="alignnone size-full wp-image-8193" title="Photoshop a Paper Texture from Scratch then Create a Grungy Web Design with it!" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/2.jpg" alt="Photoshop a Paper Texture from Scratch then Create a Grungy Web Design with it!" width="580" height="300" /></a></p>
<h2>How To Create a Clean and Colorful Web Layout</h2>
<p><a href="http://www.tutorial9.net/tutorials/photoshop-tutorials/create-a-clean-and-colorful-web-layout-in-photoshop/"><img class="alignnone size-full wp-image-8195" title="How To Create a Clean and Colorful Web Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/3.jpg" alt="How To Create a Clean and Colorful Web Layout" width="580" height="300" /></a></p>
<h2>Design a Beautiful Website From Scratch</h2>
<p><a href="http://net.tutsplus.com/tutorials/html-css-techniques/design-a-beautiful-website-from-scratch/"><img class="alignnone size-full wp-image-8196" title="Design a Beautiful Website From Scratch" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/5.jpg" alt="Design a Beautiful Website From Scratch" width="580" height="300" /></a></p>
<h2>Design a trendy business &amp; finance layout</h2>
<p><a href="http://www.grafpedia.com/tutorials/design-trendy-business-finance-layout"><img class="alignnone size-full wp-image-8197" title="Design a trendy business &amp; finance layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/6.jpg" alt="Design a trendy business &amp; finance layout" width="580" height="300" /></a></p>
<h2>Design a trendy business &amp; finance layout</h2>
<p><a href="http://designinstruct.com/web-design/make-a-stylishly-elegant-portfolio-web-design-in-photoshop/"><img class="alignnone size-full wp-image-8198" title="Design a trendy business &amp; finance layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/7.jpg" alt="Design a trendy business &amp; finance layout" width="580" height="300" /></a></p>
<h2>Design a creative portfolio in Photoshop</h2>
<p><a href="http://wegraphics.net/blog/tutorials/photoshop/design-a-creative-portfolio-in-photoshop/"><img class="alignnone size-full wp-image-8199" title="Design a creative portfolio in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/8.jpg" alt="Design a creative portfolio in Photoshop" width="580" height="300" /></a></p>
<h2>Create an awesome soft portfolio layout in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/create-an-awesome-soft-portfolio-layout-in-photoshop.html"><img class="alignnone size-full wp-image-8200" title="Create an awesome soft portfolio layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/9.jpg" alt="Create an awesome soft portfolio layout in Photoshop" width="580" height="300" /></a></p>
<h2>Create a Bright and Sleek Web Design in Photoshop</h2>
<p><a href="http://designinstruct.com/web-design/create-a-bright-and-sleek-web-design-in-photoshop/"><img class="alignnone size-full wp-image-8202" title="Create a Bright and Sleek Web Design in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/10.jpg" alt="Create a Bright and Sleek Web Design in Photoshop" width="580" height="300" /></a></p>
<h2>Design a clean sports web layout in magazine-style with Photoshop</h2>
<p><a href="http://wegraphics.net/blog/tutorials/photoshop/design-a-clean-sports-magazine-style-web-layout-with-photoshop/"><img class="alignnone size-full wp-image-8203" title="Design a clean sports web layout in magazine-style with Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/11.jpg" alt="Design a clean sports web layout in magazine-style with Photoshop" width="580" height="300" /></a></p>
<h2>Learn To Create A Photography Style Web Layout</h2>
<p><a href="http://www.hv-designs.co.uk/2010/05/20/learn-to-create-a-photography-style-web-layout/"><img class="alignnone size-full wp-image-8204" title="Learn To Create A Photography Style Web Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/12.jpg" alt="Learn To Create A Photography Style Web Layout" width="580" height="300" /></a></p>
<h2>How to create a distinguishable textured web layout in Photoshop</h2>
<p><a href="http://wegraphics.net/blog/tutorials/photoshop/how-to-create-a-distinguishable-textured-web-layout-in-photoshop/"><img class="alignnone size-full wp-image-8205" title="How to create a distinguishable textured web layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/13.jpg" alt="How to create a distinguishable textured web layout in Photoshop" width="580" height="300" /></a></p>
<h2>Design a Warm, Cheerful Website Interface in Adobe Photoshop</h2>
<p><a href="http://webdesign.tutsplus.com/tutorials/design-a-warm-cheerful-website-interface-in-adobe-photoshop/"><img class="alignnone size-full wp-image-8206" title="Design a Warm, Cheerful Website Interface in Adobe Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/14.jpg" alt="Design a Warm, Cheerful Website Interface in Adobe Photoshop" width="580" height="300" /></a></p>
<h2>Create a Theme Store Website Layout in Photoshop</h2>
<p><a href="http://devisefunction.com/2010/04/29/create-a-theme-store-website-layout-in-photoshop/"><img class="alignnone size-full wp-image-8207" title="Create a Theme Store Website Layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/15.jpg" alt="Create a Theme Store Website Layout in Photoshop" width="580" height="300" /></a></p>
<h2>Design The Brilliante Website Layout in Photoshop</h2>
<p><a href="http://spyrestudios.com/design-the-brilliante-website-layout-in-photoshop/"><img class="alignnone size-full wp-image-8208" title="Design The Brilliante Website Layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/16.jpg" alt="Design The Brilliante Website Layout in Photoshop" width="580" height="300" /></a></p>
<h2>Creating a Stylish Blog Design Layout in Photoshop</h2>
<p><a href="http://line25.com/tutorials/creating-a-stylish-blog-design-layout-in-photoshop"><img class="alignnone size-full wp-image-8209" title="Creating a Stylish Blog Design Layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/17.jpg" alt="Creating a Stylish Blog Design Layout in Photoshop" width="580" height="300" /></a></p>
<h2>Create an Elegant Photography Web Layout in Photoshop</h2>
<p><a href="http://designinstruct.com/web-design/create-an-elegant-photography-web-layout-in-photoshop/"><img class="alignnone size-full wp-image-8210" title="Create an Elegant Photography Web Layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/18.jpg" alt="Create an Elegant Photography Web Layout in Photoshop" width="580" height="300" /></a></p>
<h2>Create a Stylish Portfolio Site Design in Photoshop</h2>
<p><a href="http://line25.com/tutorials/create-a-stylish-portfolio-site-design-in-photoshop"><img class="alignnone size-full wp-image-8211" title="Create a Stylish Portfolio Site Design in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/19.jpg" alt="Create a Stylish Portfolio Site Design in Photoshop" width="580" height="300" /></a></p>
<h2>How to design a psd layout in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-design-a-psd-layout-in-photoshop.html"><img class="alignnone size-full wp-image-8212" title="How to design a psd layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/20.jpg" alt="How to design a psd layout in Photoshop" width="580" height="300" /></a></p>
<h2 id="post-2357">Design a creative unusual layout</h2>
<p><a href="http://www.grafpedia.com/tutorials/design-creative-unusual-layout"><img class="alignnone size-full wp-image-8213" title="Design a creative unusual layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/21.jpg" alt="Design a creative unusual layout" width="580" height="300" /></a></p>
<h2>Web Layout for Italian Restaurant</h2>
<p><a href="http://www.adobetutorialz.com/articles/2510/1/Web-Layout-for-Italian-Restaurant"><img class="alignnone size-full wp-image-8214" title="Web Layout for Italian Restaurant" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/22.jpg" alt="Web Layout for Italian Restaurant" width="580" height="300" /></a></p>
<h2>How to create a restaurant psd template in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-create-a-restaurant-psd-template-in-photoshop.html"><img class="alignnone size-full wp-image-8215" title="How to create a restaurant psd template in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/23.jpg" alt="How to create a restaurant psd template in Photoshop" width="580" height="300" /></a></p>
<h2>Design a Cartoon Grunge Website Layout</h2>
<p><a href="http://psd.tutsplus.com/interface-tutorials/design-a-cartoon-grunge-website-layout/"><img class="alignnone size-full wp-image-8222" title="Design a Cartoon Grunge Website Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/24.jpg" alt="Design a Cartoon Grunge Website Layout" width="580" height="300" /></a></p>
<h2 id="post-3456">Design an impressive web hosting layout</h2>
<p><a href="http://www.grafpedia.com/tutorials/design-impressive-web-hosting-layout"><img class="alignnone size-full wp-image-8216" title="Design an impressive web hosting layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/25.jpg" alt="Design an impressive web hosting layout" width="580" height="300" /></a></p>
<h2>How To Create a Rockin’ Website Layout In Photoshop</h2>
<p><a href="http://spyrestudios.com/rockin-website-layout-in-photoshop/"><img class="alignnone size-full wp-image-8217" title="How To Create a Rockin’ Website Layout In Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/26.jpg" alt="How To Create a Rockin’ Website Layout In Photoshop" width="580" height="300" /></a></p>
<h2>How to design a landing page or a light psd layout in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-design-a-landing-page-or-a-light-psd-layout-in-photoshop.html"><img class="alignnone size-full wp-image-8218" title="How to design a landing page or a light psd layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/27.jpg" alt="How to design a landing page or a light psd layout in Photoshop" width="580" height="300" /></a></p>
<h2>Product/Business Style Layout</h2>
<p><a href="http://www.hv-designs.co.uk/2010/06/29/productbusiness-style-layout/"><img class="alignnone size-full wp-image-8219" title="Product/Business Style Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/28.jpg" alt="Product/Business Style Layout" width="580" height="300" /></a></p>
<h2>How to create a modern portfolio layout using Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-create-a-modern-portfolio-layout-using-photoshop.html"><img class="alignnone size-full wp-image-8220" title="How to create a modern portfolio layout using Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/29.jpg" alt="How to create a modern portfolio layout using Photoshop" width="580" height="300" /></a></p>
<h2>Create a Magic Night Themed Web Design From Scratch in Photoshop</h2>
<p><a href="http://psd.tutsplus.com/tutorials/interface-tutorials/create-a-magic-night-themed-web-design-from-scratch-in-photoshop/"><img class="alignnone size-full wp-image-8221" title="Create a Magic Night Themed Web Design From Scratch in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/30.jpg" alt="Create a Magic Night Themed Web Design From Scratch in Photoshop" width="580" height="300" /></a></p>
<h2 id="post-1552">Create a Game layout – Clan Layout</h2>
<p><a href="http://www.grafpedia.com/tutorials/create-game-layout-clan-layout"><img class="alignnone size-full wp-image-8223" title="Create a Game layout – Clan Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/31.jpg" alt="Create a Game layout – Clan Layout" width="580" height="300" /></a></p>
<h2>Create a company/business web layout using Photoshop</h2>
<p><a href="http://artbox7.com/blog/tutorials/create-a-companybusiness-web-layout-using-photoshop.html"><img class="alignnone size-full wp-image-8224" title="Create a company/business web layout using Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/32.jpg" alt="Create a company/business web layout using Photoshop" width="580" height="300" /></a></p>
<h3>Watercolored Design Studio Blog Layout</h3>
<p><a href="http://psdvibe.com/2009/04/12/watercolored-design-studio-blog-layout/"><img class="alignnone size-full wp-image-8225" title="Watercolored Design Studio Blog Layout" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/33.jpg" alt="Watercolored Design Studio Blog Layout" width="580" height="300" /></a></p>
<h2>Create a real estate web layout in Photoshop</h2>
<p><a href="http://trendytuts.com/web-layout-tutorials/create-a-real-estate-web-layout-in-photoshop.html"><img class="alignnone size-full wp-image-8226" title="Create a real estate web layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/34.jpg" alt="Create a real estate web layout in Photoshop" width="580" height="300" /></a></p>
<h2>How to create a wordpress theme in Photoshop</h2>
<h2><a href="http://trendytuts.com/web-layout-tutorials/how-to-create-a-wordpress-theme-in-photoshop.html"><img class="alignnone size-full wp-image-8227" title="How to create a wordpress theme in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/35.jpg" alt="How to create a wordpress theme in Photoshop" width="580" height="300" /></a></h2>
<h2>Create Colorful Blog Web Layout Using Photoshop</h2>
<p><a href="http://www.psdeluxe.com/tutorials/web-layouts-tutorials/create-colorful-blog-web-layout/"><img class="alignnone size-full wp-image-8228" title="Create Colorful Blog Web Layout Using Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/36.jpg" alt="Create Colorful Blog Web Layout Using Photoshop" width="580" height="300" /></a></p>
<h2>Making the ‘Clean Grunge’ Blog Design</h2>
<p><a href="http://psd.fanextra.com/tutorials/designing/making-the-clean-grunge-blog-design/"><img class="alignnone size-full wp-image-8229" title="Making the ‘Clean Grunge’ Blog Design" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/37.jpg" alt="Making the ‘Clean Grunge’ Blog Design" width="580" height="300" /></a></p>
<h2>Create A Minimal Portfolio Site Design</h2>
<p><a href="http://webdesign.tutsplus.com/tutorials/complete-websites/create-a-minimal-portfolio-site-design-plus-a-free-psd/"><img class="alignnone size-full wp-image-8230" title="Create A Minimal Portfolio Site Design " src="http://www.tuttoaster.com/wp-content/uploads/2011/02/38.jpg" alt="Create A Minimal Portfolio Site Design " width="580" height="300" /></a></p>
<h2>Portfolio Layout Design Tutorial with 3D Look</h2>
<p><a href="http://www.ultimatedesignertoolkit.com/tutorials/portfolio-layout-design-tutorial-with-3d-look/"><img class="alignnone size-full wp-image-8231" title="Portfolio Layout Design Tutorial with 3D Look" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/39.jpg" alt="Portfolio Layout Design Tutorial with 3D Look" width="580" height="300" /></a></p>
<p><a href="http://trendytuts.com/web-layout-tutorials/how-to-create-a-trendycolorful-wordpress-layout-in-photoshop.html"><img class="alignnone size-full wp-image-8232" title="How to create a trendy/colorful wordpress layout in Photoshop" src="http://www.tuttoaster.com/wp-content/uploads/2011/02/40.jpg" alt="How to create a trendy/colorful wordpress layout in Photoshop" width="580" height="300" /></a></p>
<p>Many of these tutorials show detailed steps, so even the beginners can try them and for the advanced you can easily find some tips and tricks that are sure to come in handy. As they say, practice makes perfect, so try out a couple of tutorials and with photoshop here to stay for the long haul, you don’t need to worry about it becoming outdated. Did we miss any of your favorite tutorials? Which one was your favorite? Please let us know by commenting below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/40-great-photoshop-user-interface-tutorials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Ultimate Background Removal Guide with PhotoShop</title>
		<link>http://www.tuttoaster.com/the-ultimate-background-removal-guide-with-photoshop/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-ultimate-background-removal-guide-with-photoshop</link>
		<comments>http://www.tuttoaster.com/the-ultimate-background-removal-guide-with-photoshop/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 08:28:31 +0000</pubDate>
		<dc:creator>Sergiu Naslau</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[eraser]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[removal]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=7884</guid>
		<description><![CDATA[A picture is worth 1000 words. But what if I wanna &#8220;cut&#8221; some of those words and create my own message? GNU Image Manipulation Program (GIMP) and Adobe Photoshop are two of the most popular image editing tools out there. In this article, we will look at Photoshop&#8217;s capabilities. Photoshop offers us the possibility to [...]]]></description>
			<content:encoded><![CDATA[<p>A picture is worth 1000 words. But what if I wanna &#8220;cut&#8221; some of those words and create my own message? GNU Image Manipulation Program (GIMP) and Adobe Photoshop are two of the most popular image editing tools out there. In this article, we will look at Photoshop&#8217;s capabilities. Photoshop offers us the possibility to remove a subject from a photo, but how to do that? Which tool will do the best job?</p>
<h3>Getting started!</h3>
<p>Photoshop offers us a bunch of tools for background removing, but lets take a closer look at this. To actually remove the background or a subject from a picture, first thing you have to do is to select it. Because of this, I have split up this process in two parts:</p>
<ul>
<li><strong>The selector tools.</strong></li>
<li><strong>The eraser tools.</strong></li>
</ul>
<p>The selector tools offer us the power to delimit the subject, so in later actions we can copy or remove it. The tools are:</p>
<ul>
<li>the lasso tools;</li>
<li>the pen tool;</li>
<li>quick/magic selection tools;</li>
<li>quick mask;</li>
<li>the color range app;</li>
</ul>
<p>The eraser tools remove the pixels from inside the selection, or outside the selection.<br />
This  tools are:</p>
<ul>
<li>the eraser tools.</li>
<li>the extract filter.</li>
</ul>
<p>Note: even if every tool has a different objective they will not always give the best results, that is why a combination of them all will create the perfect selection/background removal.<span id="more-7884"></span></p>
<h3>Lasso Tool</h3>
<p>One of the oldest tools offered by Photoshop, the lasso tool a beautiful way to select something fast and with no headaches. The lasso tool lets us create a continuous manual selection by click around the subject.</p>
<p><strong>Photo Source</strong>: <a href="http://www.sxc.hu/photo/1274956">Yellow Flower</a></p>
<p>So we have this nice photo of a flower, with a cleare contrast that will help me show you how to use the lasso tool.But first thing, create a new copy of the photo, in case we do to much damage, or need to compare the final result, we can go back to the original and see.</p>
<p><img src="/wp-content/uploads/css/pictures/lasso_lt/mar1.png" alt="#" width="600" height="375" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/the-ultimate-background-removal-guide-with-photoshop/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to Convert a Slick PSD Design to XHTML/CSS</title>
		<link>http://www.tuttoaster.com/how-to-convert-a-slick-psd-design-to-xhtmlcss/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-convert-a-slick-psd-design-to-xhtmlcss</link>
		<comments>http://www.tuttoaster.com/how-to-convert-a-slick-psd-design-to-xhtmlcss/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 05:06:44 +0000</pubDate>
		<dc:creator>Cody Robertson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[slicing]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=7127</guid>
		<description><![CDATA[Converting a Adobe PSD to a static HTML/CSS page can be quite the hassle, so today I will demonstrate how to go about the process. We are going to take the PSD template below and convert it to a fully XHTML/CSS layout that works in all major browsers (IE6+). The page is essentially broken down [...]]]></description>
			<content:encoded><![CDATA[<p>Converting a Adobe PSD to a static HTML/CSS page can be quite the hassle, so today I will demonstrate how to go about the process. We are going to take the PSD template below and convert it to a fully XHTML/CSS layout that works in all major browsers (IE6+). The page is essentially broken down to five major sections, each one having its own container wrapping custom content. We will approach this conversion by first writing valid XHTML code then add CSS to make the page resemble the PSD. Lets begin by looking at the PSD and what we want to take from it.</p>
<blockquote><p>Click on the image to download the psd files for <span id="more-7127"></span>this tutorial.</p></blockquote>
<p><a href="http://cl.ly/2PIX"><img src="http://www.tuttoaster.com/wp-content/uploads/2010/09/photography-psd-template-thumb.png" alt="Photography PSD Template" width="580" height="569" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/how-to-convert-a-slick-psd-design-to-xhtmlcss/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Ruby for PHP Developers</title>
		<link>http://www.tuttoaster.com/ruby-for-php-developers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ruby-for-php-developers</link>
		<comments>http://www.tuttoaster.com/ruby-for-php-developers/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 07:08:17 +0000</pubDate>
		<dc:creator>Jose</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=6899</guid>
		<description><![CDATA[With our knowledge of PHP we can learn a lot about Ruby. Use of variables, loops, arrays, functions and classes, everything starting from PHP. In the end, there is an example to see all together where we&#8217;ll combine what we have learnt to see something really useful in action. Brief Introduction We could say PHP [...]]]></description>
			<content:encoded><![CDATA[<p>With our knowledge of PHP we can learn a lot about Ruby. Use of variables, loops, arrays, functions and classes, everything starting from PHP. In the end, there is an example to see all together where we&#8217;ll combine what we have learnt to see something really useful in action.</p>
<h2>Brief Introduction</h2>
<p>We could say PHP and Ruby (plus a framework) are the most used language in the Internet. There are many reasons, but the best one for our purpose is they are very similar in some points. So we are going to learn Ruby using those points as a support, and, trust me, if you know a little bit more about PHP than echo, it&#8217;s going to be pretty easy to learn the basis of Ruby.</p>
<p>These are the steps you need to follow to install Ruby in your operating system.</p>
<ul>
<li>Windows: Download the package from the official web: <a href="http://www.ruby-lang.org/en/downloads/">Ruby Downloads</a>.</li>
<li>Mac OS X: Preinstalled.</li>
<li>Linux: Just type: &#8220;sudo apt-get install ruby-full&#8221;.</li>
<li>Other Operating Systems: Go to the official page <a href="http://www.ruby-lang.org/en/downloads/">Ruby Downloads</a>.</li>
</ul>
<h2>Variables</h2>
<p>Ruby is a dynamic language, just like PHP, <span id="more-6899"></span>so we don&#8217;t need to define a variable. The difference here is the types, Ruby is a strongly typed language, so if we want to convert an integer into a string we need to call the proper function. Take a look at this couple of examples using variables in PHP and Ruby.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	$number = 3;
	echo &quot;The number is &quot; . $number;
?&gt;
</pre>
<pre class="brush: ruby; title: ; notranslate">
number = 3
puts &quot;The number is &quot; + number.to_s
</pre>
<p>These scripts have the same objective, concatenate a number to a string, and display the result. We can observe the first differences with PHP:</p>
<ul>
<li>The echo function of PHP is &#8220;puts&#8221; in Ruby. We use puts to show the result of a function or just for debugging purposes.</li>
<li>There is no end of line with semicolon, so the line finishes when a new one starts.</li>
<li>The concatenation in Ruby is made with the plus sign, not with point.</li>
<li>As we have said before, in Ruby we need to convert the type integer into string to show it. (In the PHP example we just use it, and the programming language takes care of its conversion).</li>
<li>As you might guess, there is a function for every type conversion, so we have &#8220;to_i&#8221; to integer, &#8220;to_f&#8221; to float and &#8220;to_s&#8221; to string.</li>
</ul>
<h2>Arrays and other structured variables</h2>
<p>The use of arrays is as simple as in PHP, basically we can do most of the things we do in PHP with the tools Ruby offers us. Let&#8217;s see the first step to use arrays, its creation and the access to them. By default the index of an array starts in 0.</p>
<pre class="brush: ruby; title: ; notranslate">
# Simple array with 3 elements
animals = ['dogs', 'cats', 'spiders']
puts animals[2] # third element

# Another way to create an array
cars = Array.new
cars &amp;lt;&amp;lt; 'BMW'
cars &amp;lt;&amp;lt; 'Toyota'
cars &amp;lt;&amp;lt; 'Ford'
puts cars[0]

# Hash (or array with not integer keys)
h = Hash[&amp;quot;this_is_a_key&amp;quot;, 100, &amp;quot;other_key&amp;quot;, 200]
puts h['other_key']
</pre>
<p>The output is:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/1.jpg" alt="Simple Array" width="600" height="249" /></p>
<p>Pretty simple, right? Well, besides of those methods we have some more for working with arrays, in PHP you have similar ways to get the same data, but in Ruby is even easier.</p>
<pre class="brush: ruby; title: ; notranslate">
animals = ['dogs', 'cats', 'spiders']

puts animals.first # Output: dogs
puts animals.last  # Output: spiders
puts animals.length  # Output: 3
</pre>
<p>In the last three lines there is an important point to be noticed. We called animals.first instead of first(animals). That&#8217;s because arrays are objects. But arrays are not the only ones, strings, numbers, hashes are also objects. As we have seen in the last example, <strong>we&#8217;ll usually call to a function with something like &#8220;x.function&#8221; instead of &#8220;function(x)&#8221;.</strong></p>
<h2>Conditionals, loops and functions</h2>
<h3>Conditionals</h3>
<p>We have seen the basics of Ruby, but we need more to do something useful. Ruby has the same classic conditionals that PHP: if, else, elsif (not elseif!). All the conditionals structures finishes with &#8220;end&#8221;, and we don&#8217;t have to put parenthesis like in PHP, it&#8217;s optional in Ruby.</p>
<pre class="brush: ruby; title: ; notranslate">
number = 70

if number &gt; 90
	puts 'This number is near to 100'
elsif number &gt; 50
	puts 'This number is greater than 50'
else
	puts 'This number is less than 50'
end

# The output will be: 'This number is greater than 50'
</pre>
<h3>Loops and functions</h3>
<p>In PHP the loops and functions are as simple as in Ruby. In Ruby we have basically similar loops to the ones we have in PHP, but the syntax is a little bit different, let&#8217;s kill two birds with one stone and see the functions and loops in the same example, trust me, it&#8217;s going to be easy.</p>
<pre class="brush: ruby; title: ; notranslate">
# Function definition
def show_elements(array)
	array.each_with_index do |element,index|  # Similar to foreach in PHP
		puts &quot;#{element} is in the array at #{index} position.&quot;
	end
end

animals = ['dogs', 'cats', 'spiders']
# We call the function
show_elements(animals) # We can also call it with &quot;show_elements animals&quot;
</pre>
<p>Its output is going to be:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/2.jpg" alt="Each in Ruby" width="600" height="267" /></p>
<p>Let&#8217;s see the others loops. Here we have a typical while where we increment a counter, very similar to the while in PHP, right?</p>
<pre class="brush: ruby; title: ; notranslate">
times = 4

now = 1
while now &lt;= times
    puts &quot;Iteration number #{now} of #{times}&quot;
    now += 1
end
</pre>
<p>There is one kind of loop we have in Ruby and not in PHP, the &#8220;until&#8221;, its use is very simple, so in the next example we&#8217;ll see it with the for loop.</p>
<pre class="brush: ruby; title: ; notranslate">
times = 4
now = 1
until now &gt; times
    puts &quot;until #{now} of #{times} times&quot;
    now += 1
end

for i in 1..4
   puts &quot;Looping around 4 times (#{i})&quot;
end
</pre>
<p>Take a look at the output, and check if it makes sense for you.</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/3.jpg" alt="Loops Ruby" width="600" height="307" /></p>
<p>Both iterate the same amount of times. The for in Ruby is just like in PHP, but the syntax it&#8217;s a little bit cleaner. We don&#8217;t have to put the parenthesis in any of them, but we could, like in PHP. The only way we have to tell Ruby the loop ends, is the &#8220;end&#8221; reserve word</p>
<blockquote><p>&#8220;All the conditional and loops finishes with the end reserve word&#8221;</p></blockquote>
<p>Other loop, actually a Ruby style loop, is &#8220;times&#8221;. Yes, we say the number of times we want to repeat something, just like this:</p>
<pre class="brush: ruby; title: ; notranslate">
5.times do
   puts 'Impossible to be cleaner' # This will puts the string 5 times
end
</pre>
<p>We don&#8217;t have this loop in PHP, but it&#8217;s very useful if we know before the execution the exactly number of iterations we need.</p>
<h2>Class Definition</h2>
<p>Like PHP, Ruby is an object oriented language, which means we are going to have classes, methods and attributes. Take a look at this class in Ruby</p>
<pre class="brush: ruby; title: ; notranslate">
# define the class company
class Company
  def initialize(name, owner)
    # attributes of Company's class
    @name = name
    @owner = owner
  end

  # method new_product
  def new_product
    puts 'The new product is coming out!'
  end

  # method describe
  def describe
    puts &quot;Hi, I'm #{@owner} and my company is #{@name}&quot;
  end
end
</pre>
<p>The first difference we can notice here is the attributes definition. In Ruby we usually define them into the constructor or just with the sets and gets (we&#8217;ll see them later). And those attributes are defined by the @ just before its name, like @name. The definition of methods is also very simple, just with the &#8220;def&#8221; and &#8220;end&#8221; reserve words.</p>
<p>But like PHP, the class definition does nothing itself, so let&#8217;s use it (this code must be right after the class definition).</p>
<pre class="brush: ruby; title: ; notranslate">
# class company definition
# ...
comp = Company.new('Free Cars', 'Ray')
comp.describe #Output: Hi, I'm Ray and my company is Free Cars

# Error in 3, 2, 1...
puts comp.owner #Output: NoMethodError: undefined method ‘owner’
</pre>
<p>The output will be:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/4.jpg" alt="Error in class" width="600" height="286" /></p>
<p>We have to notice two things in the example. First of all, we can&#8217;t access to an attribute without its getter. The other important thing is that the error is displayed after we run the program and see the result of calling &#8220;describe&#8221; (yes, like in PHP, most things happen when the script is running, so <strong>the execution goes on until there is an error or the script ends</strong>).</p>
<p>If we try to access to &#8220;owner&#8221; we&#8217;ve got an error. So we need something (hint: it will be a method) to get the content of the attribute.</p>
<h2>Gets and Sets in Classes</h2>
<p>The gets and sets (also known as getters and setters) are the methods to access and modify the private attributes of a class. As you might know is a very good practice to use them (just like in PHP). The difference here is that is almost obligatory, and we have a little help from the language.</p>
<pre class="brush: ruby; title: ; notranslate">
class Company
 attr_accessor :name # Set and Get in a line
 def initialize(name, owner)
    # attributes of Company's class
    @name = name
    @owner = owner
  end
end

comp = Company.new('Free Cars', 'Ray')
puts comp.name
comp.name = 'Old Cars'
puts comp.name
</pre>
<p>The output, now without errors:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/5.jpg" alt="Class without errors" width="600" height="236" /></p>
<p>With the attr_accessor we &#8220;declare&#8221; the set and the get method for the attribute. Actually, we usually declare the set and the method just for setting and getting the attribute. Despite this, there is a way to do more things in the set or the get method, but we won&#8217;t really need it. The point is we can access now to &#8220;name&#8221;!</p>
<blockquote><p>&#8220;With attr_accessor we have the get and the set method at the same time&#8221;</p></blockquote>
<h2>Let&#8217;s put it all together!</h2>
<p>In this last section, we are going to build a class with methods and use them, but we&#8217;ll use everything we&#8217;ve just learned. The good news here are we know PHP, so let&#8217;s use it to remember the Ruby&#8217;s syntax!</p>
<p>The class is going to model a factory and remember, take a look at the way we program it, and the differences with PHP, more than the use of the class.</p>
<pre class="brush: ruby; title: ; notranslate">
class Factory
	#sets and gets for all the attributes
	attr_accessor :name, :creation_year, :use_of_floors

	# The class constructor
	def initialize(name,creation_year,use_of_floors)
    	@name = name
    	@creation_year = creation_year
    	@use_of_floors = use_of_floors
   	end

	def description
	   puts &quot;This factory is #{@name} and was created in #{@creation_year}&quot;
	end

	def report_of_floors
		@use_of_floors.each_with_index do |element,index|
			puts &quot;The floor number #{index} is used for #{element}&quot;
		end
	end
end

a = Factory.new('Apple',1976,['Reception','Production','Offices'])

a.description
a.report_of_floors
</pre>
<p>And the output for this final script is:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/6.jpg" alt="Final Example" width="600" height="274" /></p>
<hr />
<h2>Conclusion</h2>
<p>This language, as many others, has many things we have to learn before we can call ourselves developers, but this tutorial covers the first steps using the knowledge of PHP to build actual programs. You can continue with more details in the official documentation.</p>
<p>I hope you liked it. Thank you for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/ruby-for-php-developers/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Creating a Upload/Download System Using PHP Classes</title>
		<link>http://www.tuttoaster.com/creating-a-uploaddownload-system-using-php-classes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-a-uploaddownload-system-using-php-classes</link>
		<comments>http://www.tuttoaster.com/creating-a-uploaddownload-system-using-php-classes/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 00:43:54 +0000</pubDate>
		<dc:creator>Cody Robertson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[upload]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=4590</guid>
		<description><![CDATA[Making a PHP upload script can be a very challenging task when you are just starting out, heck; it’s still hard to some extent when you are an experienced developer. So today, I’m going to show you how to make one using PHP5 Classes and a simple form. In the script we will be able [...]]]></description>
			<content:encoded><![CDATA[<p>Making a PHP upload script can be a very challenging task when you are just starting out, heck; it’s still hard to some extent when you are an experienced developer. So today, I’m going to show you how to make one using PHP5 Classes and a simple form. In the script we will be able to upload files with certain file extensions and set a limit to the size of the file we want to upload. This will all go along with a sharing link and a force download script.</p>
<h3>The Basic Upload Form</h3>
<p>First we are going to start out just by making our upload form where we will be able to select a file and then press the upload button to upload the file into our certain directory we will define. It is quite basic so you can just copy and paste it.</p>
<pre class="brush: php; title: ; notranslate">&lt;form action=&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
&lt;input name=&quot;file&quot; type=&quot;file&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Upload&quot; /&gt; &lt;/form&gt;
</pre>
<h3>Developing the Upload Class</h3>
<h4>The Class and Variables</h4>
<p>Now we need to start on the server side part of our project. We need to start by defining a simple class with the name of “Upload”. Inside of that we are going to want to have 3 protected variables; $path, $max_file_length, and $extensions. Our $path variable is going to be the relative path to the upload directory. Our $max_file_size variable will be our maximum allowed file size in megabytes and our $extensions variable will be <span id="more-4590"></span>an array with our allowed file extensions.</p>
<h4>The Functions</h4>
<p>In our class we will have 3 different functions; upload_file(), download_file() and show_notification(). The name of each function should tell you what it does, so we are going to move on and first set up our show_notification function.</p>
<h4>Show Notification Function</h4>
<p>In our function we are going to pass through 2 different parameters; one for the message or messages and one for the type of noticfiation. (eg: error, notice, success). We will then open a unordered list and echo out each message in a list element inside the list.</p>
<pre class="brush: php; title: ; notranslate">public function show_notification($items, $type) {
echo &quot;
&lt;ul class=&quot;$type&quot;&gt; \n&quot;;
if(count($items) &gt; 1) {
foreach($items as $item) {
echo &quot;
	&lt;li&gt;$item&lt;/li&gt;
\n&quot;;
}
}
else {
echo &quot;
	&lt;li&gt;$items&lt;/li&gt;
\n&quot;;
}
echo &quot;&lt;/ul&gt;
\n&quot;;
}</pre>
<h4>The Upload Function</h4>
<p>Our upload function is next, we want to create a function that takes the uploaded file and move it to our uploads directory so it can be shared and downloaded by other users. We will start by opening up the function and see if the was a post request for upload a file.</p>
<pre class="brush: php; title: ; notranslate">public function upload_file() {
//Check for upload request:
if(isset($_FILES['file'])) {
//What to do with the file
}
}</pre>
<p>Now we are going to make an array to store the file information in so we can access it easily. There are 5 different items we are going to store in the array; name, type, size, tmp_name and error (if any).</p>
<pre class="brush: php; title: ; notranslate">//Set File Information:
$file = array(
'name' =&gt; $_FILES['file']['name'],
'type' =&gt; $_FILES['file']['type'],
'size' =&gt; $_FILES['file']['size'],
'temp' =&gt; $_FILES['file']['tmp_name'],
'error' =&gt; $_FILES['file']['error']
);</pre>
<p>Next, we will check if there is no errors, and if there is not we will file through the file extension to see if that certain file type is allowed. We will use a variable $filetype_ok to check later if the file is in fact an acceptable file to this point. We will use our protected array of $extensions to reference the allowed file types.</p>
<pre class="brush: php; title: ; notranslate">
 //Check for file error:
if($file['error'] == 0) { foreach($this-&gt;extensions as $extension) { if($extension == $file['type']) { //Filetype ok! $filetype_ok = true; } }  //No match but no error: if(!isset($filetype_ok)) { $filetype_ok = false; } } else { //Filetype/error okay?: $filetype_ok = false; }
</pre>
<p>Then, we need to check if we ended up with $filetype_ok being true or false, and if it is true we will check if our file is a acceptable range size-wise for upload to our server. If it is not a allowed type or is too big for are server we will show a notification using our function.</p>
<p>&nbsp;</p>
<pre class="brush: php; title: ; notranslate"> //Is Filetype ok?
if($filetype_ok) {
//Check if it is under the max size limit
if($file['size'] &gt; ($this-&gt;;max_file_size * 1048576)) {
//File ok!, Move file:
else {
$this-&gt;show_notification('Your file is too big to upload to our server.', 'error');
}
}
else {
$this-&gt;show_notification('File type not allowed.', 'error');
}
</pre>
<p>Finally, we now have create a unique filename for our file and move it to our upload directory. We will make a unique name by using the mt_rand function and creating a random number 0-5000 then assigning that number to the beginning of our file following an underscore. Then we will use the move_uploaded_file function to move our file. If the file moves successfully we will echo our a sharing link!</p>
<pre class="brush: php; title: ; notranslate">
//Filename:
$filename = mt_rand(0, 5000) . '_' . $file['name'];

//Now lets more the file:
$move_file = move_uploaded_file($file['temp'], $this-&gt;path . $filename . '.');

if($move_file) {
//File uploaded:
$this-&gt;show_notification('File successfully uploaded. Look below for status and link.', 'success');
echo '
Download Link:';
echo '
&lt;input id=&quot;download&quot; type=&quot;text&quot; value=&quot;http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?file=' . $filename . '&quot; /&gt;';
}
</pre>
<p>Our final code for the upload function should look like this.</p>
<pre class="brush: php; title: ; notranslate">
public function upload_file() {
//Check for upload request:
if(isset($_FILES['file'])) {
//Set File Information:
$file = array(
'name' =&gt; $_FILES['file']['name'],
'type' =&gt;; $_FILES['file']['type'],
'size' =&gt; $_FILES['file']['size'],
'temp' =&gt; $_FILES['file']['tmp_name'],
'error' =&gt; $_FILES['file']['error']
);

//Check for file error:
if($file['error'] == 0) {
foreach($this-&amp;gt;extensions as $extension) {
if($extension == $file['type']) {
//Filetype ok!
$filetype_ok = true;
}
}

//No match but no error:
if(!isset($filetype_ok)) {
$filetype_ok = false;
}
}
else {
//Filetype/error okay?:
$filetype_ok = false;
}

//Is Filetype ok?
if($filetype_ok) {
//Check if it is under the max size limit
if($file['size'] &lt; ($this-&gt;max_file_size * 1048576)) {
//Filename:
$filename = mt_rand(0, 5000) . '_' . $file['name'];

//Now lets more the file:
$move_file = move_uploaded_file($file['temp'], $this-&gt;;path . $filename . '.');

if($move_file) {
//File uploaded:
$this-&gt;show_notification('File successfully uploaded. Look below for status and link.', 'success');
echo '
Download Link:';
echo '
&lt;input id=&quot;download&quot; type=&quot;text&quot; value=&quot;http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?file=' . $filename . '&quot; /&gt;';
}
}
else {
$this-&gt;show_notification('Your file is too big to upload to our server.', 'error');
}
}
else {
$this-&gt;show_notification('File type not allowed.', 'error');
}
}
}
</pre>
<h4>The Download Function</h4>
<p>For this upload/download system when a user clicks the sharing link for a file the system will force a download of the file using PHP Headers. This is for the ease of use and it is a way to save bandwidth.We will first see is the file is set through a $_GET variable and then see if that file exists in our upload directory.</p>
<pre class="brush: php; title: ; notranslate">
function download_file() {
//Check for download request:
if(isset($_GET['file'])) {
//Make sure there is a file before doing anything
if(is_file($this-&gt;path . basename($_GET['file']))) {
//Force download through headers:
else {
$this-&gt;show_notification('File not found!', 'error');
}
}
}
</pre>
<p>Now, guess what we have to do, put a little snippet in so the famous Internet Explorer does what we want it to do (Never heard of that before).</p>
<pre class="brush: php; title: ; notranslate">
//Below required for IE:
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
</pre>
<p>Finally, we need to set the headers that will force the download. These are pretty generic headers that most can be figured out by just reading the parameters in head functions. Look at the end of the tutorial for a link to all header descriptions.</p>
<pre class="brush: php; title: ; notranslate">
//Set Headers:
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($this-&gt;path . basename($_GET['file']))) . ' GMT');
header('Content-Type: application/force-download');
header('Content-Disposition: inline; filename=&quot;' . basename($_GET['file']) . '&quot;');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($this-&gt;path . basename($_GET['file'])));
header('Connection: close');
readfile($this-&gt;path . basename($_GET['file']));
exit();
</pre>
<p>There you have it, the download function is complete and the full upload and download script is complete. Below is the final download function code.</p>
<pre class="brush: php; title: ; notranslate">function download_file() {
//Check for download request:
if(isset($_GET['file'])) {
//Make sure there is a file before doing anything
if(is_file($this-&gt;path . basename($_GET['file']))) {
//Below required for IE:
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

//Set Headers:
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($this-&gt;path . basename($_GET['file']))) . ' GMT');
header('Content-Type: application/force-download');
header('Content-Disposition: inline; filename=&quot;' . basename($_GET['file']) . '&quot;');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($this-&gt;path . basename($_GET['file'])));
header('Connection: close');
readfile($this-&gt;path . basename($_GET['file']));
exit();
}
else {
$this-&gt;show_notification('File not found!', 'error');
}
}
}
</pre>
<p>Implementing It Into Your PageHere is finally the part that makes it all work, we need to add 3 lines at the top of the file. The first is to include the class, second to create the instance, and third to register the download function.</p>
<p>&nbsp;</p>
<p>Now just add this one line right before our form (or wherever you want the upload notification/sharing links to show).</p>
<p>The final index file should look like this (This is a example case).</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;
&lt;div id=&quot;wrapper&quot;&gt;
&lt;div id=&quot;header&quot;&gt;
&lt;h1&gt;Creating a Upload/Download System Using PHP Classes&lt;/h1&gt;
&lt;/div&gt;
&lt;div id=&quot;content&quot;&gt;
&lt;div id=&quot;upload&quot;&gt;
&lt;form action=&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;&quot; enctype=&quot;multipart/form-data&quot; method=&quot;post&quot;&gt;
&lt;input id=&quot;real_upload&quot; class=&quot;hide&quot; name=&quot;file&quot; type=&quot;file&quot; /&gt;
&lt;input id=&quot;real_submit&quot; class=&quot;hide&quot; type=&quot;submit&quot; value=&quot;Upload&quot; /&gt;
&lt;div id=&quot;upload_hack&quot;&gt;
&lt;input id=&quot;fake_upload&quot; onclick=&quot;select_file()&quot; readonly=&quot;readonly&quot; /&gt;
&lt;input id=&quot;fix&quot; onclick=&quot;upload_file()&quot; readonly=&quot;readonly&quot; value=&quot;UPLOAD&quot; /&gt;&lt;/div&gt;
&lt;br class=&quot;fix&quot; /&gt;
&lt;/form&gt;
&lt;div id=&quot;notifications&quot;&gt;upload_file(); ?&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;footer&quot;&gt;

&lt;a href=&quot;#&quot;&gt;Creating a Upload/Download System Using PHP Classes&lt;/a&gt; by &lt;a href=&quot;tuttoaster.com&quot;&gt;tuttoaster.com&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>As a little bonus you’ll get the CSS for free.</p>
<pre class="brush: css; title: ; notranslate">
body {
background: #f4f4f4;
font: 12px Arial;
}

h1 {
font: bold 24px Arial;
line-height: 30px;
}

a  {
color: #000;
text-decoration: none;
}

p {
color: #919191;
}

#wrapper {
margin: 0 auto;
width: 425px;
}

#header, #content, #notifications, #footer {
margin: 30px 0;
}

#upload_hack {
margin: -20px 0 0;
}

#upload_hack input {
background: #FFF;
border: 0px solid #e1e1e1;
-webkit-box-shadow: 0px 0px 5px #c4c4c4;
color: #919191;
float: left;
font-weight: bold;
height: 14px;
margin: 0 10px 0 0;
padding: 21px;
width: 253px;
}

#upload_hack #fix {
background: #FFF;
border: 0px solid #e1e1e1;
-webkit-box-shadow: 0px 0px 5px #c4c4c4;
color: #000;
float: left;
font-weight: bold;
height: 14px;
padding: 21px;
width: 68px;
}

#download {
background: #FFF;
border: 0px solid #e1e1e1;
-webkit-box-shadow: 0px 0px 5px #c4c4c4;
color: #919191;
float: left;
font-weight: bold;
height: 14px;
margin: 10px 0 30px 0;
padding: 21px;
width: 385px;
}

.success {
color: #4fc416;
font-weight: bold;
list-style-image: url('success.png');
list-style-type: none;
}

.error {
color: #f05429;
font-weight: bold;
list-style-image: url('error.png');
}

.success li, .error li {
height: 30px;
line-height: 30px;
}

.fix {
clear: both;
}

.hide {
opacity: 0.0;
}</pre>
<p>Final Thoughts/Closing CommentsThis upload/download system is nowhere near advanced. This is where you come in, as a developer I love seeing people build off my basic or even advanced scripts and make them better. So here is my challenge to you, download our script and look it over and make any improvement you have for it and post below, we can all learn from each other!</p>
<p>&nbsp;</p>
<h4>Links for header(); Function Information</h4>
<ul>
<li><a href="http://php.net/manual/en/function.header.php">PHP:header – Manual</a></li>
<li><a href="http://www.w3schools.com/php/func_http_header.asp">PHP Header Function –W3Schools</a></li>
</ul>
<h3>Please don&#8217;t abuse this demo, files will be removed on a weekly base.</h3>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/creating-a-uploaddownload-system-using-php-classes/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to Create a Forum in PHP from Scratch</title>
		<link>http://www.tuttoaster.com/how-to-create-a-forum-in-php-from-scratch/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-a-forum-in-php-from-scratch</link>
		<comments>http://www.tuttoaster.com/how-to-create-a-forum-in-php-from-scratch/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 08:46:46 +0000</pubDate>
		<dc:creator>Jose</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=4786</guid>
		<description><![CDATA[In this tutorial we&#8217;ll see how to make a forum using PHP and MySQL. We have to cover a lot of different things, so let&#8217;s start! Some details about this tutorial You can download a compressed folder with the whole project inside. So sometimes I won&#8217;t show all the code of a file in order [...]]]></description>
			<content:encoded><![CDATA[<p><!-- Post Begins Here --></p>
<p>In this tutorial we&#8217;ll see how to make a forum using PHP and MySQL. We have to cover a lot of different things, so let&#8217;s start!</p>
<h3>Some details about this tutorial</h3>
<ul>
<li>You can download a compressed folder with the whole project inside. So sometimes I won&#8217;t show all the code of a file in order to focus on the important parts of the project.</li>
<li>The code I&#8217;ll show is exactly the same than the one you can download, except for some comments. In the original project you&#8217;ll have everything well documented (using phpDocumentor).</li>
<li>I&#8217;ll ommit the &lt;?php and ?&gt; tags in the tutorial, but every time you type PHP code in a file you should put it between them.</li>
<li>This project doesn&#8217;t follow a MVC pattern, but we&#8217;ll use classes and try to separate the different functionalities.</li>
</ul>
<h3>What and how</h3>
<p><strong>What</strong> are we going to do? We have to think the answer very carefully, and not only &#8220;a forum&#8221;, also the functionality we want to offer.</p>
<p><strong>Answer</strong>: We are going to develop a forum where anyone can write a post without registration and other people can see it and write a response.<span id="more-4786"></span></p>
<p><strong>How</strong> are we going to do that? Here we have to think about how we are going to organize the project, the files..etc</p>
<p><strong>Answer</strong>: As you know we are going to use PHP and MySQL. The files are going to be organized by the code they implement, so a class file will be in a different folder than a CSS file, for instance.</p>
<h3>Designing and Building the Database</h3>
<p>When we start to code a project, the first thing we usually do is to think about the database. Because that decision is going to be very important, and a lot of the PHP code depends on it.</p>
<p>There are many options here, we could make a table of posts and another of users, even three tables if we want, but we&#8217;ll take the easiest way in order to focus on the PHP code.</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/dbSchema.png" alt="DB Schema" width="209" height="240" /></p>
<p>This table is all we need, at least for a simple forum like ours.</p>
<p>So a thread is going to consist of several rows in the table. The first post of a thread is going to have the permalink_parent set to NULL, and the rest of them are going to have the permalink_parent with the permalink of their parent, as the name suggests.</p>
<p>To create the table we have to execute the following sentence in our database:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE `posts` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `title` varchar(128) COLLATE utf8_bin NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `content` text COLLATE utf8_bin NOT NULL,
  `permalink_parent` varchar(128) COLLATE utf8_bin DEFAULT NULL,
  `author` varchar(128) COLLATE utf8_bin NOT NULL,
  `permalink` varchar(128) COLLATE utf8_bin DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `upermalink` (`permalink`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
</pre>
<p>The lengths of some fields depend on how many people are going to use the forum, but these values are enough for the moment.</p>
<p>Note that we are defining an UNIQUE KEY over the permalink column, which means that in our forum a title must be unique, I know we usually can post a couple of threads with the same title in other forum, however for the sake of simplicity we are keeping the title as unique.</p>
<h3>File Organization</h3>
<p>As well as designing the database we need to think about how we are going to organize the project, instead of starting to code without a previous plan.</p>
<p>The title and permalink are going to be unique, so we have to check if a title is taken.</p>
<p>At this point we can also take different approaches, we should try to keep things as simple as we can. So this is a little schema of our final project.</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/schema.jpg" alt="File Schema" width="209" height="305" /></p>
<p>As you can see there are many files, but all of them are necessary if we want to keep things organized. Let&#8217;s see them step by step, and try to get the techniques we&#8217;ll use.</p>
<h3>The media folder</h3>
<p>This tutorial is focus on the PHP side, so I won&#8217;t explain too much about the CSS and the HTML code, you can download all the code at the end of this tutorial, so don&#8217;t worry. Anyway I&#8217;ll try to summarize the content of this folder.</p>
<ul>
<li><strong>style.css</strong>. It&#8217;s the CSS file for all the forum, includes the reset CSS code and the rest of the styles like a regular CSS file.</li>
<li><strong>bg_container.png</strong>. The background of the main container.</li>
<li><strong>bg_body.png</strong>. The background of the body element.</li>
</ul>
<h3>The Configuration File</h3>
<p>This file is going to be useful from almost every script of the project. There are different options to implement it, but probably the most used is just a file with some define() lines, like this:</p>
<pre class="brush: php; title: ; notranslate">
define('DB_HOSTNAME','hostname');
define('DB_USERNAME','user');
define('DB_PASSWORD','password');
define('DB_NAME','forum');

define('RE_PUBLIC_KEY','Your recaptcha public key');
define('RE_PRIVATE_KEY','Your recaptcha private key');
</pre>
<p>I&#8217;ll explain later the two last lines. So from now on every time we include the file we can get the value of a constant with something as simple as this:</p>
<pre class="brush: php; title: ; notranslate">
require_once 'config.inc.php';

echo DB_HOSTNAME; //output: hostname
</pre>
<h3>Header and Footer</h3>
<p>There is a part of the HTML code that isn&#8217;t going to change so we can write once and include the file every time we need it. This is very simple and it will save us time and lines of code.</p>
<h4>Header</h4>
<p>The header.html file will have all we need to build the first part of a page: the doctype tag, the html, head, the beginning of the body element, the link to the CSS file&#8230;</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot;content=&quot;text/html; charset=UTF-8&quot;&gt;
	&lt;title&gt;TutToaster Forum [Demo]&lt;/title&gt;
	&lt;link href=&quot;media/style.css&quot; media=&quot;all&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
	&lt;!--[if !IE 7]&gt;
	&lt;style type=&quot;text/css&quot;&gt;
		#wrap {display:table;height:100%}
	&lt;/style&gt;
	&lt;![endif]--&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;wrap&quot;&gt;
	&lt;div id=&quot;header_wrap&quot;&gt;
		&lt;div id=&quot;header&quot;&gt;
			&lt;h1&gt;&lt;a href=&quot;index.php&quot;&gt;TutToaster Forum [Demo]&lt;/a&gt;&lt;/h1&gt;
		&lt;/div&gt;&lt;!-- End #header--&gt;
	&lt;/div&gt;&lt;!-- End #header_wrap--&gt;
	&lt;div id=&quot;main&quot;&gt;
</pre>
<p>As you can see the #main and #wrap divs, the body and html tags are open so we have to close them in the footer.</p>
<h4>Footer</h4>
<p>The footer.html file is very similar, we&#8217;ll include it when we finish the output to &#8220;close&#8221; the page.</p>
<pre class="brush: php; title: ; notranslate">
	&lt;/div&gt; &lt;!-- End main--&gt;
&lt;/div&gt;  &lt;!-- End Wrap--&gt;
&lt;div  id=&quot;footer_wrap&quot;&gt;
	&lt;div id=&quot;footer&quot;&gt;
		&lt;div id=&quot;footer_right&quot;&gt;
			&lt;p&gt;Forum made by Jose for TutToaster. You can see the whole tutorial &lt;a href=&quot;http://www.tuttoaster.com/how-to-create-a-forum-in-php-from-scratch&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
		&lt;/div&gt; &lt;-- End footer_right--&gt;
	&lt;/div&gt; &lt;!-- End footer--&gt;
&lt;/div&gt; &lt;!-- End footer_wrap--&gt;

&lt;script type=&quot;text/javascript&amp;quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	$('input, textarea').click(function(){
		$(this).select();
	});
    if ($(&quot;#message_header p&quot;).html()) {
		setTimeout(function() {
			$(&quot;#message_header&quot;).slideUp('slow');
		}, 5000);
	}
</pre>
<p>We are loading the jQuery at the bottom of our page, which is a good practice, because the rest of the site will be rendered before we execute any jQuery code.</p>
<p>The jQuery code is basically to improve the interface, so when a user clicks on an input field all the text will be selected. The if works in this way: when we see the p element (in #message_header) has something, then we hide it with the slideUp effect after 5 seconds. You can see this code working in the live demo after you try to post a message with an empty field or if the title you have selected is already taken.</p>
<p>The difference between require and include is the include() construct will emit a warning if there is an error (script goes on) and require() will emit a fatal error (script stops). As you may guess, adding _once to those statements we prevent the file from being included twice. Let me show you the final result with something very simple like this:</p>
<pre class="brush: php; title: ; notranslate">
require_once 'header.html';

echo &quot;A very simple message&quot;;

require_once 'footer.html';
</pre>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/header_footer.jpg" alt="Header and footer with a simple message" width="600" height="414" /></p>
<p>Great! Now we have our &#8220;template&#8221; and all we need to output will be shown between the header and the footer code as long as we include these files.</p>
<h3>The Database class</h3>
<p>In order to separate the PHP code that is going to execute SQL queries and the rest of PHP code we&#8217;ll make a database class, this class will connect to the database, get some rows and save data.</p>
<p>If we think about it, if an object always need to connect to the database, the connection code must be in the constructor. So every time we create an object that object is going to be ready to execute queries with the function mysql_query().</p>
<p>Also, the methods we&#8217;ll need are going to depend on the rest of code, but here I show you the beginning of the class as it will be in the end of the development:</p>
<pre class="brush: php; title: ; notranslate">

require_once 'config.inc.php';

class Database
{

	private $db;

	function __construct()
	{
		// We set our own error_handler
		set_error_handler(array($this,'errorHandler'));

		//Connect to Database
		$this-&gt;db = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
		mysql_set_charset('utf8', $this-&gt;db);
	 	mysql_select_db(DB_NAME, $this-&gt;db);
	}

	function errorHandler($errno, $errstr)
	{
		switch ($errno){
		    case E_WARNING:
				echo '&lt;b&gt;There has been an error with the MySQL database connection. '.
				  	 'Please, make sure the config file is OK.&lt;/b&gt;';
				die();
		    default:
		        return false;
		}
	}

	function getThreads()
	{
		$query = &quot;SELECT p.title, date_format(p.date,'%m/%d/%Y %T') as date, p.permalink, p.author &quot;.
				 &quot;FROM posts p &quot;.
				 &quot;WHERE permalink_parent IS NULL&quot;;
		return mysql_query($query);
	}

	// ... other useful methods ....

}
</pre>
<p>Probably the most important method is savePost, so let&#8217;s take a look at it apart from the previous ones.</p>
<pre class="brush: php; title: ; notranslate">
function savePost($input, $permalink, $newThread)
{

	$postOK = $this-&gt;isValidPost($input, $permalink, $newThread);

	if (!$postOK) {
		return -1;  // something missing
	}

	if ($newThread) {
		$query = 'INSERT INTO posts '
				. '(title, content, author, permalink, permalink_parent) VALUES'
				. '(&quot;%s&quot;,&quot;%s&quot;,&quot;%s&quot;,&quot;%s&quot;, NULL)';

		$query = sprintf($query,
			clean(strip_tags($input[&quot;title&quot;])),
			clean(strip_tags($input[&quot;content&quot;])),
			clean(strip_tags($input[&quot;author&quot;])),
			$permalink);
	} else {
		$query = 'INSERT INTO posts '
				. '(content, permalink_parent, author) VALUES'
				. '(&quot;%s&quot;,&quot;%s&quot;,&quot;%s&quot;)';

		$query = sprintf($query,
			clean(strip_tags($input['content'])),
			$permalink,
			clean(strip_tags($input['author'])));
	}

	if (mysql_query($query)) {
		return 1;   // Ok
	} elseif (mysql_errno() == 1062) {
		return -2;  // Duplicated title error
	} else {
		return -3;  // DB error
	}
}
</pre>
<p>Note when we create the $query string, we use sprintf to make the code cleaner.</p>
<p>The method isValidPost is private and its code is:</p>
<pre class="brush: php; title: ; notranslate">
private function isValidPost($input, $permalink, $newThread)
{
	if ($newThread) {
		return !empty($input['title'])
			&amp;&amp; !empty($input['content'])
			&amp;&amp; !empty($input['author'])
			&amp;&amp; !empty($permalink);
	} else {
		return !empty($input['content'])
			&amp;&amp; !empty($input['author'])
			&amp;&amp; !empty($permalink);
	}
}
</pre>
<p>The different numbers we return in the savePost method have a meaning (we&#8217;ll see it later), but, basically we have to recognize different kind of errors to show a different message each time, so we can&#8217;t return just false, and the use of exceptions could be complicated for the beginners.</p>
<p>This is actually a classic approach to manage the database from the PHP code, we&#8217;ll see at the end of the tutorial what people are using now and why we should use it too. But this class is enough for us and I assume readers know a little bit about PHP probably also know this way to connect to the database and manage queries.</p>
<h3>Validation Helper</h3>
<p>This script (helpers/validation.php) is just a group of functions we&#8217;ll use all over the project. There are 3 functions here:</p>
<h4>String to Permalink (strToPermalink)</h4>
<p>Takes a string as input and creates a human-friendly URL string. Its implementation is:</p>
<pre class="brush: php; title: ; notranslate">
function strToPermalink($str)
{
	$permalink = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
	$permalink = preg_replace(&quot;/[^a-zA-Z0-9\/_|+ -]/&quot;, '', $permalink);
	$permalink = strtolower(trim($permalink, '-'));
	$permalink = preg_replace(&quot;/[\/_|+ -]+/&quot;, '_', $permalink);

	return $permalink;
}
</pre>
<p>To sum up all we do here is to remove &#8220;weird&#8221; characters like á or é and others, and then convert -, spaces and others into _. (Permalink is also known as slug or even permanent link).</p>
<h4>Clean input (clean)</h4>
<p>Here we take care of removing slashes if magic_quotes_gpc is enabled and escaping some characters with mysql_real_escape_string. Don&#8217;t worry if you don&#8217;t know what magic quotes are or why we code this function, when we talk about security you&#8217;ll understand it.</p>
<pre class="brush: php; title: ; notranslate">
function clean($value)
{
	// Stripslashes
	if (get_magic_quotes_gpc()) {
		$value = stripslashes( $value );
	}

	// Quote if not a number or a numeric string
	if (!is_numeric($value) &amp;&amp; !empty($value)) {
		$value = mysql_real_escape_string($value);
	}
	return $value;
}
</pre>
<h4>Process post (processPost)</h4>
<p>This function has a lot of lines (compare to the rest of this file), I&#8217;ll try to explain all of them without code:</p>
<ol>
<li>Prepare the array to be returned with all values initialized as NULL</li>
<li>If it has everything in the array to start, then checks if the Recaptcha answer is OK, generates the permalink, tries to save the post and returns a message.</li>
<li>If the input array is not empty but it hasn&#8217;t got all we need OR the Recaptcha input field is wrong, then it returns an error message.</li>
<li>Finally, the showBox variable in the array is set. The box we&#8217;ll be shown if there was an error, or always in case we are in the page where users can write a response.</li>
</ol>
<p>I&#8217;ll explain Recaptcha later, now let&#8217;s focus on the rest of the code. The array it will return is initialized in this way:</p>
<pre class="brush: php; title: ; notranslate">

/* This is not neccesary but it makes code cleaner,
and we could change this new array and without modifying
the original $_POST */
$input = $_POST;

$returnArray = array('errorHTML' =&gt; NULL,
					 'okMessage' =&gt; NULL,
					 'recaptchaError' =&gt; NULL,
					 'showBox' =&gt; NULL);
</pre>
<p>Then we code the steps 2 and 3 of the list we did before.</p>
<pre class="brush: php; title: ; notranslate">
if (array_sum($input) &gt; 0 &amp;&amp; !empty($input[&quot;recaptcha_response_field&quot;])) {
	//We have something in the $input and the Recaptcha response
	$resp = recaptcha_check_answer (RE_PRIVATE_KEY,
		$_SERVER[&quot;REMOTE_ADDR&quot;],
		$input[&quot;recaptcha_challenge_field&quot;],
		$input[&quot;recaptcha_response_field&quot;]);
	if ($resp-&gt;is_valid) {
		require_once 'classes/Database.php';
		$db = new Database();

		if (is_null($permalink)){
			$permalink = strToPermalink(strip_tags($input['title']));
		}

		$saveResult = $db-&gt;savePost($input,
									clean(strip_tags($permalink)),
									$newThread);

		switch ($saveResult) {
			case -1:  //A field is empty
				$returnArray['errorHTML'] = 'All fields are required';
				break;

			case -2: //The title is already in use
				$returnArray['errorHTML'] = 'Duplicated title, please, choose another one.';
				break;
			case -3: //There has been an error with the query
				$returnArray['errorHTML'] = 'There has been an error with the Database, '.
										'please, try again later.';
				break;

			default: //Everything is OK
				$returnArray['okMessage'] = '&lt;p&gt;The post has been published. You can see it '
					.'&lt;a href=&quot;view_thread.php?permalink=' . $permalink . '&quot;&gt;here&lt;/a&gt;&lt;/p&gt;';
		}
	} else { //The recaptcha response is not valid.
		$returnArray['recaptchaError'] = $resp-&amp;gt;error;
	}
} elseif (array_sum($input) &amp;gt; 0) {
	//We have something in the $input array but the recaptcha response is not
	$returnArray['errorHTML'] = 'All fields are required';
}
</pre>
<p>You can see here the different kind of errors we return and the reasons. Finally we set the showBox variable of $returnArray:</p>
<pre class="brush: php; title: ; notranslate">
if ($newThread) {
	$returnArray['showBox'] = !empty($returnArray['errorHTML'])
	|| !empty($returnArray['recaptchaError'])
	|| empty($input);
}
</pre>
<h3>The View Class</h3>
<p>There is a part of the HTML code that depends on some parameters that come from PHP. To keep things as clear as we can we are going to make a class exclusively for this purpose.</p>
<p>The home page is going to show a list of threads, so let&#8217;s code that method and the constructor of our new class:</p>
<pre class="brush: php; title: ; notranslate">
// we need the class db to make an object
require_once 'Database.php';

//we'll also need the recaptcha helper later
require_once 'helpers/recaptcha.php';

class View{

	private $db;

	function __construct()
	{
		$this-&gt;db = new Database();
	}

    function tableThreads()
	{
		$content = &quot;&quot;;

		if (($threads = $this-&gt;db-&gt;getThreads()) &amp;&amp; mysql_num_rows($threads) &gt; 0) {
			 $content .= '&lt;h1&gt;Threads&lt;/h1&gt;';
			 $content .= '&lt;table border=&quot;0&quot; width=&quot;&quot; id=&quot;posts_list&quot;&gt;';
			 $content .= '&lt;tr&gt;';
			 $content .= '&lt;th class=&quot;title&quot;&gt;Title&lt;/td&gt;';
			 $content .= '&lt;th&gt;Date&lt;/td&gt;';
			 $content .= '&lt;th&gt;User&lt;/td&gt;';
			 $content .= '&lt;/tr&gt;';

			while ($row = mysql_fetch_assoc($threads)) {
				$content .= '&lt;tr class=&quot;thread&quot;&gt;';
				$content .= '&lt;td class=&quot;title&quot;&gt;';
				$content .= '&lt;a href=&quot;view_thread.php?permalink=';
				$content .= htmlspecialchars($row['permalink']) . '&quot;&gt;'.$row['title'].'&lt;/a&gt;';
				$content .= '&lt;/td&gt;';
				$content .= '&lt;td class=&quot;date&quot;&gt;'.htmlspecialchars($row['date']).'&lt;/td&gt;';
				$content .= '&lt;td class=&quot;author&quot;&gt;'.htmlspecialchars($row['author']).'&lt;/td&gt;';
				$content .= '&lt;/tr&gt;';
			}
			$content .= '&lt;/table&gt;';
			return $content;
		} else {
			return false;
		}
	}
</pre>
<p>The htmlspecialchars function provides a way to change some HTML elements into entities, so every time we are going to output something from the database we should use this function. We&#8217;ll se more about this later.</p>
<p>The next method we&#8217;ll code is composeTable, and it will be useful to show all the posts of a thread.</p>
<pre class="brush: php; title: ; notranslate">
// ... previous code ...

private function composeTable($post, $firstPost, $numRows)
{
	$htmlTable = &quot;&quot;;

	if ($firstPost)
		$htmlTable .= '&lt;h1&gt;'.htmlspecialchars($post['title']).'&lt;/h1&gt;';

	$htmlTable .= '&lt;table border=&quot;0&quot; width=&quot;895&quot;&gt;';
	$htmlTable .= '	&lt;tr&gt;';
	$htmlTable .= '		&lt;th&gt;Message&lt;/th&gt;';
	$htmlTable .= '		&lt;th&gt;Date&lt;/th&gt;';
	$htmlTable .= '		&lt;th&gt;Author&lt;/th&gt;';
	$htmlTable .= '	&lt;/tr&gt;';
   	$htmlTable .= '	&lt;tr&gt;';
	$htmlTable .= '		&lt;td class=&quot;title&quot;&gt;'.htmlspecialchars($post['content']).'&lt;/td&gt;';
	$htmlTable .= '		&lt;td class=&quot;date&quot;&gt;'.htmlspecialchars($post['date']).'&lt;/td&gt;';
	$htmlTable .= '		&lt;td class=&quot;author&quot;&gt;'.htmlspecialchars($post['author']).'&lt;/td&gt;';
	$htmlTable .= '	&lt;/tr&gt;';
	$htmlTable .= '&lt;/table&gt;';
	if ($firstPost &amp;&amp; $numRows &amp;gt; 1)
		$htmlTable .= '&lt;h1&gt;Responses&lt;/h1&gt;';

	return $htmlTable;
}

function tableThreadContent($permalink)
{
	$content = &quot;&quot;;

	if ($posts = $this-&gt;db-&gt;getContentThread($permalink)) {
		$num_rows = mysql_num_rows($posts);
		if ($num_rows &gt; 0) {
			while($row = mysql_fetch_assoc($posts))
				$content .= $this-&gt;composeTable($row,
					is_null($row['permalink_parent']),
					$num_rows);
		}
		return $content;
	} else {
		return false;  //database error
	}
}

[/html]

&lt;p&gt;The second method goes around all the posts in a thread and composes the HTML with the first one (composeTable). &lt;/p&gt;

&lt;p&gt;The method composeTable is private because we'll only call it from the tableThreadContent method in the same class and its functionality is only useful inside this class. In the future if we want to make a class that extends this one and uses that method all we need to do is change private for protected.&lt;/p&gt;

&lt;p&gt;Now let's think about what happens if we don't have a single thread. Apart from being very sad it could be a problem if we don't show a warning message. This is a very simple method to do that:&lt;/p&gt;
1
// ... previous code ...
function htmlError($from_view_thread = false)
{
	if ($from_view_thread) {
		//From view_thread.php
	   	$html = '&lt;p class=&quot;error&quot;&gt;There is no thread with this title. Sorry! ';
		$html .= 'You can go back to &lt;a href=&quot;index.php&quot;&gt;the main page&lt;/a&gt;.&lt;/p&gt;';
	}else{
		// From index.php
	   	$html = '&lt;p class=&quot;error&quot;&gt;There aren\'t any threads. Sorry! &lt;/p&gt;';
	}
	return $html;
}
</pre>
<p>If we call the method from view_thread.php it means we are in a thread that doesn&#8217;t exist, so we show a different message in that case.</p>
<p>Now we need to create a form for users who want to send new posts (responses or the beginning of a new thread).</p>
<h4>Recaptcha or how to avoid spam</h4>
<p>At this point we have to think about the spam problem. As you can see there is no registration process so anyone can just fill the form and post a message with the content they want every time they like. How to handle the input will be discussed later, but the problem here is a bot could fill the form and submit it.</p>
<p>How can we avoid that? Well, the easiest and probably most used solution is a captcha system. Yes, those boring images of characters we have to identify and replicate. Specifically the implementation bought by Google, Recaptcha.</p>
<p>But what are the guarantees? Well, Twitter uses it in the sign up process and if we forum doesn&#8217;t grow too much (actually like Amazon or Google) we won&#8217;t have more problems. The question now is: how can we use it?</p>
<p>Recaptcha provides a file (in our project is helpers/recaptcha.php) and there we have all the functions we need, actually even more. You can see the documentation at the the end of the tutorial.</p>
<p>Finally, the other two methods are messageBox and buttonPostThread. The first one will return a string with the HTML needed to compose a post (a form) when we need to and the second one just returns a div to go to post_message.php and create a new post.</p>
<pre class="brush: php; title: ; notranslate">
// ... previous code ...
function messageBox($new, $recaptchaError = null, $errorHTML = null)
{
	$content = '&lt;div&gt;';
	if (!empty($errorHTML)) {
		$content .= '&lt;div&gt;&lt;p class=&quot;error&quot;&gt;' . $errorHTML . '&lt;/p&gt;&lt;/div&gt;';
	}
	if ($new) {
		$content .= '&lt;h1&gt;Post a Message&lt;/h1&gt;';
	} else {
		$content .= '&lt;h1&gt;Post a Response&lt;/h1&gt;';
	}
	$content .= '&lt;form action=&quot;&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot;&gt;';
	if ($new) {
		$content .= '';
	}
	$content .= '';
	$content .= '&lt;textarea name=&quot;content&quot; rows=&quot;8&quot; cols=&quot;88&quot;&gt;Message&lt;/textarea&gt;';
	$content .= recaptcha_get_html(RE_PUBLIC_KEY, $recaptchaError);
	$content .= '';
	$content .= '&lt;/form&gt;';
	$content .= '&lt;/div&gt;';

	return $content;
}
</pre>
<p>The $new parameter indicates if the form will be shown in post_message.php to send a new thread or in view_thread.php (to send a response). This will helps, for instance, to ask for the title of the thread if it&#8217;s going to be a new one or not.</p>
<p>The $recaptchaError is what we need to render properly the box with the captcha and the input, because in case the user types wrong the code the recaptcha_get_html will take care of showing a message.</p>
<p>Finally, the $errorHTML could contain an string of an error and we have to show it here. (We&#8217;ll see later what kind of errors could happen).</p>
<p>The last method will be buttonPostThread, and as I&#8217;ve said before its only functionality will be to return a string, but the reason we make it is to keep consistent the idea of not writing HTML code in some scripts like index.php or view_thread.php, besides of that the code of these pages will be very clear if we keep that idea in mind.</p>
<pre class="brush: php; title: ; notranslate">
// ... previous code ...
function buttonPostThread()
{
	return '&lt;div class=&quot;newThread&quot;&gt;'
		  .'&lt;a href=&quot;post_message.php&quot;&gt;Create a new thread&lt;/a&gt;'
		  .'&lt;/div&gt;';
}
</pre>
<p>Probably you are thinking: &#8220;why all this code if we haven&#8217;t written a script which shows anything directly?&#8221;. And it&#8217;s OK you wonder that, but now you will see the advantages of having a modular and independent code.</p>
<h3>Home page</h3>
<p>Let&#8217;s start with our first page, index.php. These are the things we have to show:</p>
<ul>
<li>Header</li>
<li>List of threads OR a warning if there aren&#8217;t threads</li>
<li>Link to make a new thread</li>
<li>Footer</li>
</ul>
<p>The code is as simple as this list:</p>
<pre class="brush: php; title: ; notranslate">
require_once 'classes/View.php';
require_once 'header.html';

$view = new View();

if ($htmlString = $view-&gt;tableThreads()) {
	echo $htmlString;
} else {
	echo $view-&gt;;htmlError();
}

echo $view-&gt;buttonPostThread();

require_once 'footer.html';
</pre>
<p>The output in the browser with 3 threads is:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/index.jpg" alt="Home" width="600" height="391" /></p>
<h3>Create a new post</h3>
<p>The post_message.php script is going to show a form, get the input and try to process this input as a new post. If everything is ok we&#8217;ll show the link to the new post, otherwise we&#8217;ll show an error message.</p>
<pre class="brush: php; title: ; notranslate">
require_once 'classes/View.php';
require_once 'helpers/validation.php';
require_once 'header.html';

$result = processPost();

if ($result['showBox']) {
	$view = new View();
	echo $view-&gt;messageBox(true, $result['recaptchaError'], $result['errorHTML']);
} else {
	echo $result['okMessage'];
}

require_once 'footer.html';
</pre>
<p>The processPost function is implemented in helpers/validation.php and, as I&#8217;ve explained before, processes the input, tries to save the post and return an array with different values. This is the output in Firefox:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/post_message.jpg" alt="Post Message" width="600" height="414" /></p>
<h3>View Thread</h3>
<p>The view_thread.php script will combine a couple of things.</p>
<ul>
<li>We have to get some posts, the initial one first, and show them properly.</li>
<li>The form to write a response is going to be almost the same than the one we did to write a new thread. (Hint: We&#8217;ll use the same function).</li>
</ul>
<p>The first thing we do is to include all the files we need and clean the input ($_GET) with a function (implemented in the helpers/validation.php file).</p>
<pre class="brush: php; title: ; notranslate">
require_once 'classes/View.php';
require_once 'helpers/validation.php';
require_once 'header.html';

$view = new View();
$permalink = clean($_GET['permalink']);
</pre>
<p>Here we process the $_POST array and create a &#8220;message box&#8221;, a form to send a response to the thread.</p>
<pre class="brush: php; title: ; notranslate">
// .. previous code ...

$postInput = $_POST;

$result = processPost($permalink, false);

$messageBox = $view-&gt;;messageBox(false,
	$result['recaptchaError'],
	$result['errorHTML']);
</pre>
<p>Finally we print the posts and the form to write a new response. In case we get a false value from messageBox we&#8217;ll show an error because there isn&#8217;t a thread with that permalink.</p>
<pre class="brush: php; title: ; notranslate">

if ($htmlString = $view-&gt;tableThreadContent($permalink)) {
	echo $htmlString;
	echo $messageBox;
} else {
	echo $view-&gt;htmlError(true);
}

require_once 'footer.html';
</pre>
<p>So all these parts together compose our view_thread.php script. Here we have the final result with a thread and a response to the first post:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/view_thread.jpg" alt="View Thread" width="600" height="408" /></p>
<h3>MySQL from PHP alternatives</h3>
<p>We have used some functions to manage the database like:</p>
<pre class="brush: php; title: ; notranslate">
mysql_connect();
mysql_set_charset();
mysql_select_db();
mysql_query();
</pre>
<p>The reason I&#8217;ve used these functions is because they are well known by the most of novice PHP developers, but you should know these functions have lost their popularity. I&#8217;ll explain you why.</p>
<p>Actually, there are many reasons, the mysql functions provide a procedural interface, doesn&#8217;t support a lot of things in the new versions of MySQL (newer than 4.1.3) and have more security problems. So take a look at the alternatives:</p>
<h4>MySQL Improved (mysqli)</h4>
<p>This extension was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. Some features are:</p>
<ul>
<li>Object-oriented interface</li>
<li>Support for Prepared Statements</li>
<li>Support for Transactions</li>
<li>&#8230;</li>
</ul>
<p>Apart from that is more secure than the mysql classic extension because we can use bound parameters (details in links at the conclusion).</p>
<h4>PHP Data Objects (PDO)</h4>
<p>The main difference is this API can be used with any kind of database (in theory), that means it doesn&#8217;t have to be MySQL. So the change of the database system in the project it&#8217;s going to be easier.</p>
<p>But like yin yang there is a disadvantage, some advanced new features of new MySQL versions are not supported. Anyway is usually better use this or the previous alternative than the classic mysql extension.</p>
<h4>Comparative from official documentation</h4>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/08/comparative.jpg" alt="Comparative of MySQL extensions" width="600" height="761" /></p>
<p>The details of how to use mysqli or PDO are in the official documentation.</p>
<h3>The security issue</h3>
<p>First of all I have to say I&#8217;m not a security expert but if you are going to make a web app you need to know the possible security holes, and try to prevent attacks, not being a hacker doesn&#8217;t mean you don&#8217;t need to know about security. So let&#8217;s see the most common attacks in a web app, and how to prevent them in our forum.</p>
<h4>Cross Site scripting (XSS)</h4>
<p>XSS exists when your PHP code outputs some data that has neither been filtered nor escaped. Some code like this is vulnerable to XSS:</p>
<pre class="brush: php; title: ; notranslate">
echo $_POST['var1'];
</pre>
<p>That means someone could send whatever they want in a form and will be shown later, and that&#8217;s very dangerous. The simplest thing they can send is:</p>
<pre class="brush: plain; title: ; notranslate">
alert('This will be shown instead of a real var1!!')
</pre>
<p>So the the code will be executed by the browser. A more dangerous use, could be extract cookie content with javascript and log in a system using that cookie. So, now we have understood it&#8217;s dangerous, how can we prevent it?</p>
<p>We have to escape data which comes from users. In this forum we have made a couple of things. First of all we strip the HTML and PHP code with strip_tags(), and when we show data from database we escape using htmlspecialchars(). Let&#8217;s see some code:</p>
<pre class="brush: php; title: ; notranslate">
// The user sends this:
// $_POST['email'] = &quot;alert('fool!')&quot;;
// $_POST['name'] = &quot;&lt;strong&gt;Hercules&lt;/strong&gt;&quot;;

// Now we remove all the HTML and PHP code
$email = strip_tags($_POST['email']);

echo $email; //Output: alert('fool')
echo $name; //Output: Hercules
</pre>
<p>As you can see the script tags are not shown so the alert will not be executed. But Hercules wanted to show his name with strong tags, and actually it&#8217;s harmless, but we removed those tags too. A possible solution is to provide a list of our own tags and then replace them with the actual HTML elements. We haven&#8217;t implemented this, but it would be very easy:</p>
<pre class="brush: php; title: ; notranslate">
$string = strip_tags($_POST['name']);
$string = str_replace('[strong]','&lt;strong&gt;');
$string = str_replace('[/strong]','&lt;/strong&gt;');
</pre>
<p>The other thing we do is to use htmlspecialchars(), this is redundant because with strip_tags HTML code will be removed and not inserted into our database, but there are some characters which do nothing so we can convert them into HTML entities. Remember it&#8217;s usually better to a be a little bit paranoid when we talk about security.</p>
<pre class="brush: php; title: ; notranslate">
// From database
$result = &quot;alert('ups!')&quot;;

$resultOK = htmlspecialchars($result);

echo $resultOK; //Output: alert('ups!')
</pre>
<p>The output is exactly the string, but some characters are actually HTML entities, so the code is not executed, just shown in the browser.</p>
<h4>SQL injection</h4>
<p>This vulnerability is, as the name suggests, when someone injects SQL code into your web app. Here we have to take care of a couple of details, but let&#8217;s see the main problem.</p>
<p>We have a query with some variables from $_POST, something like:</p>
<pre class="brush: php; title: ; notranslate">
$user = $_POST['user'];
$password = $_POST['password'];

$query = &quot;SELECT name, age, credit_card
		  FROM users
		  WHERE username = '$user' AND password = '$password' &quot;;
</pre>
<p>What if someone sends: <em>&#8216; or 1=1 ; &#8211;</em> as the password? The query would be:</p>
<pre class="brush: sql; title: ; notranslate">
SELECT name, age, credit_card
FROM users
WHERE username = 'jose' AND password = '' or 1=1 ; -- '
</pre>
<p>So the WHERE condition is always true because (1=1) is, and (false) || (true) is also true. Consequence? The query selects all the records.</p>
<p>A simple way to prevent this is to use the function mysql_real_escape_string() which escapes special characters in a string taking into account the current character set of the connection so that it is safe to place it in a mysql_query(), as we do in the clean function (helpers/validation.php file).</p>
<p>But still there could be a problem with slashes and magic_quotes. To summarize magic_quotes is something annoying and we have to deal with it. Magic quotes is a deprecated PHP configuration that, when turned on it automatically escapes characters for you.</p>
<p>The problem is sometimes we don&#8217;t want that, so in our forum when we clean the input we use stripslashes() in case magic_quotes is turned on, which un-quotes a quoted string, and from that point we escape the data. (see clean function at the beginning of this tutorial). So with this implementation we can insert O&#8217;connor, and it won&#8217;t be a problem, without this consideration, the input could be inserted as O\&#8217;Connor into the database.</p>
<p>There could be a problem with the magic_quotes_sybase configuration, but, apart from being deprecated, it&#8217;s turned off by default so usually it won&#8217;t be a problem, and in our forum we don&#8217;t deal with it.</p>
<p>If we had used other alternative to manage the database from PHP, a lot of these precautions wouldn&#8217;t be necessary, you have more details in the official documentation.</p>
<h4>Cross-Site Request Forgery (CSRF)</h4>
<p>According to Wikipedia, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts. But we don&#8217;t have to worry about that since our forum is open to anyone who wants to write and there aren&#8217;t sign up and log in processes. Anyway at the conclusion you have some links in case you want to know more about this exploit.</p>
<h3>How to set up your own forum</h3>
<p>When you download the code, you have to follow the next steps to have your own forum working:</p>
<ul>
<li>Get a Recaptcha key <a href="http://recaptcha.net/whyrecaptcha.html">here</a>.</li>
<li>Create a database with the SQL query at the beginning of the tutorial.</li>
<li>Change the values of constants in the config.inc.php file with yours.</li>
<li>And, of course, put the files where you can access with PHP and Apache working (localhost&#8217;s directory).</li>
</ul>
<h2>Conclusion</h2>
<p>I have to admit this tutorial is long but if you read it a couple of times and take a look at the code I&#8217;m sure you&#8217;ll be able to understand all the project.</p>
<p>The organization of code in classes and files is up to the developer. And as long as we don&#8217;t write the same code over and over again, or just type queries, html and PHP code in the same file, the project will be ok. I mean, everything about make more or less classes or create a specific function is not a science. It&#8217;s more a design problem, so feel free to think about other ways to develop this forum, it will help you to be a better developer.</p>
<p>For instance I could have written a post class, or make everything procedural, but this was just an approach, and you can see the power of this in how many lines we have written in our index or post_message web pages. In addition, if we need more features the development will be very easy since everything is well documented in the files you can download.</p>
<p>There is other feature we could implement, to set the value of the inputs to the content of $_POST if it&#8217;s received, but that could make the code the code less clear, so I&#8217;ve avoid it in order to make things easier.</p>
<p>Here you have some links to some sites where you can learn more about security, PHP and MySQL.</p>
<ul>
<li><a title="Recaptcha official site" href="http://recaptcha.net/plugins/php/">Recaptcha official site</a></li>
<li><a title="Alternatives to manage a database from PHP" href="http://es2.php.net/manual/en/mysqli.overview.php">Alternatives to manage a database from PHP</a></li>
<li><a title="Writing Secure PHP Series" href="http://www.addedbytes.com/writing-secure-php/">Writing Secure PHP Series</a></li>
<li><a title="SQL injection" href="http://en.wikipedia.org/wiki/Sql_injection">SQL injection</a></li>
<li><a title="Cross site request forgeries (XSRF)" href="http://shiflett.org/articles/cross-site-request-forgeries">Cross site request forgeries (XSRF)</a></li>
<li><a title="Design Patterns in Wikipedia" href="http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29">Design Patterns in Wikipedia</a></li>
</ul>
<p><!-- Post Ends Here --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/how-to-create-a-forum-in-php-from-scratch/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Learning JavaScript and DOM with Console</title>
		<link>http://www.tuttoaster.com/learning-javascript-and-dom-with-console/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=learning-javascript-and-dom-with-console</link>
		<comments>http://www.tuttoaster.com/learning-javascript-and-dom-with-console/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 09:01:35 +0000</pubDate>
		<dc:creator>Hein</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=6791</guid>
		<description><![CDATA[In this tutorial, you are going to learn what a console is, and more importantly, how you can leverage it to learn JavaScript and DOM quickly. So let&#8217;s get started. Console? A console is not a specific project or a command-line terminal, nor is it a Xbox 360 or PS3 (though learning JavaScript and DOM [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, you are going to learn what a console is, and more importantly, how you can leverage it to learn JavaScript and DOM quickly. So let&#8217;s get started.</p>
<h2>Console?</h2>
<p>A console is not a specific project or a command-line terminal, nor is it a Xbox 360 or PS3 (though learning JavaScript and DOM on a game console will definitely be awesome <img src='http://www.tuttoaster.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). It is a separated window in a browser that let you inspect all kinds of information about JavaScript objects and DOM objects of the displaying web page, and it exposes an object of the same name (i.e. <code>console</code>) to that page, whose methods can be called to output information of your choice to the console window.</p>
<h2>What&#8217;s Wrong with alert() and My Home-made log()?</h2>
<p>You might ask, &#8220;I can display all sorts of things with alert(), what&#8217;s the point of console?&#8221; It&#8217;s true that alert() is a quick-and-dirty way to display variables, but it has a major problem: <strong>it steals focus</strong>, which will render it useless when mouse interaction or keyboard interaction is involved. That&#8217;s not the end of the story, alert() is only good at displaying primitive variables(i.e. strings, numbers, booleans), when trying to display <span id="more-6791"></span>an object, you will be prompted with something like &#8220;[object Object]&#8220;.</p>
<p>&#8220;Fine, I&#8217;ll write a custom log() function, which will nicely convert all kinds of variable into meaningful strings and inserts them directly into the document, so it won&#8217;t interfere with any interactions. Done, no console is needed.&#8221; If that&#8217;s what you are thinking, well, I wish things could be that easy, but converting objects into meaningful strings is not an easy task. You&#8217;ll have to establish a sophisticated logic, which deeply recursively iterates objects (which may also contain objects) to capture their inner structures, and displaying these structures is not an easy task too.</p>
<h2>What Makes Console So Different?</h2>
<p>A picture is worth a thousand words. So let me show you a couple of snapshots. I&#8217;ll use Google Chrome to demonstrate console, you can access it by pressing Ctrl + Shift + I, and then click the &#8220;Console&#8221; tab (the last one).</p>
<h3>Console is a Separated Window</h3>
<p>Which means it will not interfere with mouse interaction or keyboard interaction, and it doesn&#8217;t &#8220;pollute&#8221; the page.</p>
<p><img src="/wp-content/uploads/console-images/console_float.jpg" alt="console as a separated window" /></p>
<h3>Console Can Also Dock to the Main Window</h3>
<p>If you don&#8217;t have dual monitors, this is the way to go.</p>
<p><img src="/wp-content/uploads/console-images/console_dock.jpg" alt="console docks to the main window" /></p>
<h3>Console Displays Objects Tree-like</h3>
<p>Objects are displayed tree-like, and properties can be toggled.</p>
<p><img src="/wp-content/uploads/console-images/console_display_object.jpg" alt="Console displays object tree-like" /></p>
<h3>Console Has Access to All Variables Defined by the Environment and You</h3>
<p>This is the coolest feature of console. It gives you full access to the page.</p>
<p><img src="/wp-content/uploads/console-images/console_access_variables.jpg" alt="Console has access to all variables" /></p>
<h3>Console Auto-completes Your Typing</h3>
<p>So that you can focus on experimenting, and don&#8217;t have to spend too much time on typing.</p>
<p><img src="/wp-content/uploads/console-images/console_auto_complete.jpg" alt="Console auto-completes typing" /></p>
<h3>Console Indicates DOM Elements Visually</h3>
<p>This is another cool feature of console. Move your mouse over the DOM element in the console, it will be highlighted in the page. So it&#8217;s a strong indication that what DOM element it actually refers to.</p>
<p><img src="/wp-content/uploads/console-images/console_dom.jpg" alt="Console indicates DOM elements visually" /></p>
<h3>Console Exposes a <code>console</code> Object</h3>
<p>We will look at this object in great detail later on.</p>
<p><img src="/wp-content/uploads/console-images/console_api.jpg" alt="Console exposes API" /></p>
<h2>Cute, But I Don&#8217;t Use Google Chrome</h2>
<p>Don&#8217;t worry, Google Chrome isn&#8217;t the only browser that supports console. <strong>But even if you do use Google Chrome, the following sections still help</strong>, because you may want to learn different quirks about different browsers, and knowing how to invoke console on those browsers become important.</p>
<h3>Safari</h3>
<p>Safari5 has an almost identical console, which can be accessed by pressing Ctrl + Alt + C. The one in Safari4 isn&#8217;t as helpful. It displays objects as &#8220;[object Object]&#8220;. A workaround is introduced in the section labeled &#8220;IE&#8221;</p>
<p><img src="/wp-content/uploads/console-images/console_safari.jpg" alt="Safari's console" /></p>
<h3>Firefox</h3>
<p>Firefox has an excellent extension called <a href="http://getfirebug.com/">Firebug</a>, which is arguable the father of modern developer tools. You should first <a href="https://addons.mozilla.org/en-US/firefox/addon/1843/">installed it in Firefox</a>, after which, you can access it from the status bar. To see more about a DOM element in the console (e.g. the <code>document</code> object in this example), you need to click on it, and Firebug will switch to another tab, which contains all properties of that DOM element.</p>
<p><img src="/wp-content/uploads/console-images/console_firebug.jpg" alt="Firebug's console" /></p>
<h3>Opera</h3>
<p>Opera has its own integrated developer tool called <a href="http://www.opera.com/dragonfly/">Dragonfly</a>. You can access it from &#8220;Tools &#8211; Advanced &#8211; Opera Dragonfly&#8221;. Dragonfly displays objects as &#8220;[object Object]&#8220;, but you can click on them to view their inner structures. Unfortunately, this only works for objects whose properties are enumerable. Dragonfly doesn&#8217;t highlight DOM element when you hover the mouse over the returned DOM element, making it less helpful.<br />
<img class="alignnone size-full wp-image-6885" src="http://www.tuttoaster.com/wp-content/uploads/2010/08/console_dragonfly.jpg" alt="" width="599" height="398" /></p>
<h3>IE</h3>
<p>IE8&#8242;s integrated developer tool can be accessed by pressing F12. It isn&#8217;t as helpful as previous ones. It doesn&#8217;t highlight DOM elements, no auto-completion what so ever, and worst of all, it displays objects as &#8220;[object Object]&#8221; which is not clickable, making it impossible to examine objects&#8217; structures directly. For IE6 and IE7, Microsoft released a developer tool called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&amp;displaylang=en">Internet Explorer Developer Toolbar</a>, which unfortunately doesn&#8217;t have a console at all.</p>
<p>But don&#8217;t worry, Firebug to the rescue! Fortunately, Firebug team created a cross-browser version of Firebug that works with all major browsers. It&#8217;s called <a href="http://getfirebug.com/firebuglite">Firebug Lite</a>. It has a <a href="http://getfirebug.com/firebuglite#Stable">bookmarklet version</a> and a <a href="http://getfirebug.com/firebuglite#Stable">script file version</a>. Bookmarklet lets you invoke the console on any website, whereas script file lets you invoke the console before your code sends variables to it.</p>
<p>Since Firebug Lite is not part of browser, it isn&#8217;t &#8220;privileged&#8221;, which means it can&#8217;t do things like getting the line number of a particular function call, profiling for a chunk of code and some other things that need low level support, but they don&#8217;t cover the fact that Firebug Lite has a great console.</p>
<h2>OK, I&#8217;m Sold. How do I Use it Exactly?</h2>
<p>If you want to examine a JavaScript object or a DOM element, console is the definite way to do it. As you may have guessed, there are two ways to use a console: you either type directly in it, or your use the <code>console</code> object in your code.</p>
<p>The latter is desirable, because you may forget a particular characteristic the test code demonstrates, in which case you can recall it quickly just by reviewing that code, which is saved in file. Typing directly in console is more like a one-shot deal, and it&#8217;s only suitable for very trivial code.</p>
<h2>The <code>console</code> Object</h2>
<p>If a browser supports console (either natively or via Firebug Lite), it will expose an object called <code>console</code> to your JavaScript code. You can invoke its various methods to display various aspects of information of your code to the console window.</p>
<p>Let&#8217;s see what methods the <code>console</code> object has and what they do.</p>
<p>First, we should establish a test environment:</p>
<pre class="brush: xml; title: ; notranslate">	&lt;!-- Include Firebug Lite if necessary --&gt;;
	&lt;!-- &lt;mce:script mce_src=&quot;https://getfirebug.com/firebug-lite.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/mce:script&gt; --&gt;

	&lt;!-- Your test file goes here --&gt;
	&lt;script src=&quot;test.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:0--&gt;&lt;/script&gt;</pre>
<h3>console.log()</h3>
<p>This is the method you will use most of the time. It will output its arguments to the console, and yes, it accepts arbitrary number of arguments. When displayed, they are separated by space. It also supports printf-like string substitution patterns, which should be familiar to C/C++ programmer.</p>
<pre class="brush: jscript; title: ; notranslate">var s = 'string';
var i = 1;
var f = 3.2;
var o = {a: 1, b: 2, c: 3};

console.log('string', s, 'integer', i, 'float', f, 'object', o);
console.log('string %s integer %i float %f object $o', s, i, f, o);</pre>
<p><img src="/wp-content/uploads/console-images/console.log().jpg" alt="console.log()" /></p>
<p>&nbsp;</p>
<h3>console.info() / console.warn() / console.error() / console.debug()</h3>
<p>These methods are basically the same as console.log(), but they assign messages to different categories (e.g. warning category, error category, as their names suggest). console.info() is identical to console.log() in Google Chrome, for it doesn&#8217;t have an &#8220;info&#8221; category. console.debug() is designed to also output an hyperlink which points to the line where it was called, and it&#8217;s also identical to console.log() in Google Chrome, which outputs this hyperlink for all log()-like methods.</p>
<pre class="brush: jscript; title: ; notranslate">var s = 'string';
var i = 1;
var f = 3.2;
var o = {a: 1, b: 2, c: 3};

console.debug('string', s, 'integer', i, 'float', f, 'object', o);
console.info('string', s, 'integer', i, 'float', f, 'object', o);
console.warn('string', s, 'integer', i, 'float', f, 'object', o);
console.error('string', s, 'integer', i, 'float', f, 'object', o);</pre>
<p><img src="/wp-content/uploads/console-images/console.log-like().jpg" alt="console.log-like()" /></p>
<p>&nbsp;</p>
<h3>console.assert()</h3>
<p>This method acts a bit like assertions in unit testing. It tests whether the first argument is true or not. If it is, it will do nothing, otherwise, it will output an error message consisting of the other arguments.</p>
<pre class="brush: jscript; title: ; notranslate">console.assert(true, 'this will output nothing');
console.assert(false, 'this will generate an error message');</pre>
<p><img src="/wp-content/uploads/console-images/console.assert().jpg" alt="console.assert()" /></p>
<p>&nbsp;</p>
<h3>console.dir() / console.dirxml()</h3>
<p>These two methods are designed to display JavaScript objects and DOM elements, respectively, as lists. They are identical to console.log() in Goole Chrome. We will use Firebug as an example.</p>
<pre class="brush: jscript; title: ; notranslate">var o = {a: 1, b: 2, o: {a: 1, b: 2}};
console.log(o);
console.dir(o);

var div = document.createElement('div');
div.innerHTML = '&amp;lt;span&amp;gt;content&amp;lt;/span&amp;gt;';
console.log(div);
console.dirxml(div);</pre>
<p><img src="/wp-content/uploads/console-images/console.dir_dirxml().jpg" alt="console.dir() / console.dirxml()" /></p>
<p>&nbsp;</p>
<h3>console.trace()</h3>
<p>This method will outputs the stack of function calls at the point where it is called. Confused? It&#8217;s clearer with a  code example. Notice that console.trace() is not well-supported by Google Chrome (which just outputs the caller function), so we will still use Firebug as an example.</p>
<pre class="brush: jscript; title: ; notranslate">function a() {
	b();
}
function b() {
	c();
}
function c() {
	console.trace();
}
a();</pre>
<p><img src="/wp-content/uploads/console-images/console.trace().jpg" alt="console.trace()" /></p>
<p>&nbsp;</p>
<h3>console.group() / console.groupEnd() / console.groupCollapsed()</h3>
<p>These methods are designed to structure messages. They indent messages generated between console.group() and console.groupEnd() and nest them in a block that can be toggled. You can pass arbitrary number of arguments to console.group(), which will be displayed as the title of the block. console.groupCollapsed() is the same as console.group(), except that it collapses the block by default, and it&#8217;s only supported by Firebug.</p>
<pre class="brush: jscript; title: ; notranslate">console.group('string methods');
console.log('substr', 'string'.substr(1,3));
console.log('substring', 'string'.substring(1,3));
console.groupEnd();

console.group('array methods');
console.log('slice', [1,2,3,4,5].slice(1,3));
console.log('splice', [1,2,3,4,5].splice(1,3));
console.groupEnd();</pre>
<p><img src="/wp-content/uploads/console-images/console.group().jpg" alt="console.group() / console.groupEnd()" /></p>
<p>&nbsp;</p>
<h3>console.time() / console.timeEnd()</h3>
<p>As you may have guessed, these methods measure how much time have elapsed between their invokings. Many developers use them to test function performence. They accept an argument as an ID, so that console.timeEnd() knows which timer created by console.time() to stop, and it also gets displayed as a title before the actual time.</p>
<pre class="brush: jscript; title: ; notranslate">function fn1() {
	var fn = function() {};
}
function fn2() {
	var fn = new Function();
}

console.time('fn1');
for(var i = 0 ; i &amp;lt; 1000 ; ++i) {
	fn1();
}
console.timeEnd('fn1');

console.time('fn2');
for(var i = 0 ; i &amp;lt; 1000 ; ++i) {
	fn2();
}
console.timeEnd('fn2');</pre>
<p><img src="/wp-content/uploads/console-images/console.time().jpg" alt="console.time() / console.timeEnd()" /></p>
<p>&nbsp;</p>
<h3>console.profile() / console.profileEnd()</h3>
<p>These methods turn on/off the JavsScript profiler, which scrutinizes function calls in great detail. Firebug has a clearer profile result in my option. console.profile() accepts an argument as the title of the profile result.</p>
<pre class="brush: jscript; title: ; notranslate">function fn1() {
	var fn = function() {};
}
function fn2() {
	var fn = new Function();
}

console.profile('fn');
for(var i = 0 ; i &amp;lt; 1000 ; ++i) {
	fn1();
}

for(var i = 0 ; i &amp;lt; 1000 ; ++i) {
	fn2();
}
console.profileEnd();</pre>
<p><img src="/wp-content/uploads/console-images/console.profile().jpg" alt="console.time() / console.timeEnd()" /></p>
<p>&nbsp;</p>
<h3>console.count()</h3>
<p>This method will count the number of times it have been called. It accepts an argument as an ID to support multiple countings.</p>
<pre class="brush: jscript; title: ; notranslate">function a() {
	b();
	c();
	console.count('a()');
}
function b() {
	c();
	console.count('b()');
}
function c() {
	console.count('c()');
}
a();
b();
c();</pre>
<p><img src="/wp-content/uploads/console-images/console.count().jpg" alt="console.count()" /></p>
<p>&nbsp;</p>
<h3>console.exception() / console.table()</h3>
<p>Firebug supports two addtional methods that are not supported by Google Chrome or Safari. console.exception() will output its first argument as an exception object along with its function call stack, and the other arguments constitute the message. console.table() will output its first argument, which should be array of arrays or list of objects, in a tabular layout. It also accepts a second argument, which specifies columns and/or properties to be displayed. See more of console.table() <a href="http://www.softwareishard.com/blog/firebug/tabular-logs-in-firebug/">here</a>.</p>
<p>Since these methods are not widely supported. You should avoid use them.</p>
<pre class="brush: jscript; title: ; notranslate">function a() {
	b();
}
function b() {
	c();
}
function c() {
	throw new Error('something is wrong');
}

try {
	a();
} catch (e) {
	console.exception(e, 'error catched');
}</pre>
<p><img src="/wp-content/uploads/console-images/console.exception().jpg" alt="console.exception()" /></p>
<pre class="brush: jscript; title: ; notranslate">var a = [
	['a1', 'a2', 'a3'],
	['b1', 'b2', 'b3'],
	['c1', 'c2', 'c3']
];
console.table(a);

var o = {
	div: {tag: 'div', content: 'div content'},
	p: {tag: 'p', content: 'p content'},
	span: {tag: 'span', content: 'span content'}
};
console.table(o);</pre>
<p><img src="/wp-content/uploads/console-images/console.table().jpg" alt="console.table()" /></p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>Console can be a great tool for your to learn JavaScript and DOM. If you haven&#8217;t used it before, you should start now. It will accelerate your learning speed, and it is worth the time to get familiar with console. That&#8217;s all. Thanks for reading this tutorial.</p>
<p>If you are a new web design, then you should try <a href="http://www.testkingsite.com/cisco/CCNP.html">testking ccnp</a> tutorials. We have included the expert reviews, tips and resources in our <a href="http://www.testkingsite.com/cisco/CCIE.html">testking ccie</a> tutorials and <a href="http://www.testkingsite.com/cisco/CCNA.html">testking ccna</a> guides to help you learn how to create inspiring minimal web-designs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/learning-javascript-and-dom-with-console/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Code an Email Newsletter from PSD to HTML</title>
		<link>http://www.tuttoaster.com/code-an-email-newsletter-from-psd-to-html/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-an-email-newsletter-from-psd-to-html</link>
		<comments>http://www.tuttoaster.com/code-an-email-newsletter-from-psd-to-html/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 15:15:15 +0000</pubDate>
		<dc:creator>Matthew Leak</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[branding]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[corporate]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=5578</guid>
		<description><![CDATA[Last week we learned how to go about designing HTML emails. This week we&#8217;re going to turn the PSD into a functional HTML email. To code a HTML newsletter you can either code it from scratch, or use an already existing template. I personally like to use an existing template, especially the ones supplied by [...]]]></description>
			<content:encoded><![CDATA[<p>Last week we <a href="http://www.tuttoaster.com/design-an-email-newsletter-in-photoshop-2/">learned</a> how to go about designing HTML emails. This week we&#8217;re going to turn the PSD into a functional HTML email. To code a HTML newsletter you can either code it from scratch, or use an already existing template. I personally like to use an existing template, especially the ones supplied by <a title="HTML Email Templates" href="http://www.mailchimp.com/resources/html_email_templates/">Mailchimp</a> simply because they have been tried and tested and they don&#8217;t &#8216;break&#8217;. Whichever way you decide to go about coding HTML emails you need to remember the following:</p>
<p>1. Use inline CSS to control presentation, such as background colors and fonts. eg:</p>
<p>2. You have to use Tables to control the designs layout &#8211; Pure CSS Layouts just won&#8217;t cut it i&#8217;m afraid. (I hate them too)  It&#8217;s recommended that you know about HTML tables before following this tutorial as I am not going to be covering the basics of creating tables.<span id="more-5578"></span></p>
<h3>1. Setting up the Document</h3>
<p><img class="size-full wp-image-5715 alignnone" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/files.png" alt="" width="600" height="127" /> Open the PSD containing the email design and slice and export any images that are going to be used in the email.  Create a new HTML file in your IDE of choice and copy and paste the following code into the document.</p>
<pre class="brush: xml; title: ; notranslate">&lt;!-- --&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; width=&quot;100%&quot; bgcolor=&quot;#ebebeb&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot; valign=&quot;top&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p>All extra styling will be placed inside &lt;style&gt;&lt;/style&gt; and the email content will be placed between &lt;td&gt;&lt;/td&gt;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/code-an-email-newsletter-from-psd-to-html/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Design an Email Newsletter in Photoshop</title>
		<link>http://www.tuttoaster.com/design-an-email-newsletter-in-photoshop-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=design-an-email-newsletter-in-photoshop-2</link>
		<comments>http://www.tuttoaster.com/design-an-email-newsletter-in-photoshop-2/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 09:00:35 +0000</pubDate>
		<dc:creator>Matthew Leak</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[branding]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[corporate]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[designer]]></category>
		<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=5220</guid>
		<description><![CDATA[Email newsletters are becoming more and more popular with businesses, it&#8217;s almost becoming a kind of trend. It is, by far, one of the most effective ways to spread the word about up and coming projects, company news, and other business-related stuff to a potentially large audience. Obviously you need to have people on the [...]]]></description>
			<content:encoded><![CDATA[<p>Email newsletters are becoming more and more popular with businesses, it&#8217;s almost becoming a kind of trend. It is, by far, one of the most effective ways to spread the word about up and coming projects, company news, and other business-related stuff to a <em>potentially</em> large audience. Obviously you need to have people on the receiving list first, but even if you only have a small number of recipients, it doesn&#8217;t matter. An audience is an audience.</p>
<p>Creating an Email newsletter is just like creating a website. We design the final product in Photoshop and then it is delivered to readers through HTML. This first part will cover the design process of creating an email newsletter.</p>
<p><strong>Difficulty</strong>: Beginner &#8211; Intermediate<span id="more-5220"></span></p>
<h3>The Final Product</h3>
<p>Here&#8217;s an image of what the Newsletter we are going to be designing looks like.<!--more--></p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/06/tutorial.jpg" alt="" width="600" height="880" /></p>
<h3>1. Getting Started</h3>
<p>The majority of newsletters that are sent via email these days have a fixed width rather than a fluid/liquid layout. This is because email clients don&#8217;t use the full width of the screen to display an email message and the last thing you want in an email newsletter are horizontal scroll bars. So with this in mind it&#8217;s generally a good idea to design newsletters around a width of <strong>550-600px. </strong>The height doesn&#8217;t matter as much but readers may read the email in a preview pane before opening the actual email message (I do) and so it&#8217;s a good thing to remember that the average preview pane is around<strong> 30</strong><strong>0-500px</strong> in height so make sure any important bits of the email are in this area.</p>
<h3>2. Setting up Photoshop</h3>
<p>Open Photoshop and create a new document with a <strong>width of 800px</strong> and a <strong>h</strong><strong>eight of 1000px </strong>and a <strong>resolution of 72pi</strong> (make sure the colour mode is <strong>RGB</strong>, too.)</p>
<p><img class="aligncenter size-full wp-image-5195" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/1.png" alt="" width="600" height="403" />Fill the background with a nice light grey, I&#8217;m using <strong>#ebebeb</strong> and create a container with a <strong>width of 600px</strong> filled with white and position this in the centre of the document.</p>
<h3>3. Allow the user to view the email in their browser of choice</h3>
<p><strong><img src="http://www.tuttoaster.com/wp-content/uploads/2010/06/2.png" alt="" width="600" height="42" /></strong></p>
<p>It&#8217;s always good to keep accessibility in mind so make sure you give the reader the option to view the newsletter in their web browser. This is because not all clients will download images from an email by default, therefore any important graphics that you need to be shown in an email could potentially not be shown straight away. If the user wishes to the view the full message (with images) in their client then they will have to download the images to their machine. This is another good reason to give the reader the option of viewing the email in their web browser.</p>
<h3>4. Creating the email header</h3>
<p><img class="aligncenter size-full wp-image-5197" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/3.png" alt="" width="600" height="122" /></p>
<p>Grab the Rounded Rectangle tool (U) and create a selection <strong>560px wide</strong>, <strong>85px high</strong> and a <strong>corner radius of 10px <span style="font-weight: normal;">and fill it with a nice dark grey. Then with the selection made add a title for your Newsletter along with the month and some contact details if you wish. It&#8217;s a good idea to use a nice bold font so readers can clearly see what the email they&#8217;ve received actually is. For this reason I am using Myriad Pro Bold Condensed for everything in the header.</span></strong></p>
<h3>5. Creating the &#8216;main&#8217; part of the newsletter</h3>
<p><img class="aligncenter size-full wp-image-5198" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/4.png" alt="" width="600" height="196" />The main part of our Newsletter as you can see from the preview at the beginning of the post is a section that&#8217;s telling the reader they are entitled to a free bar of Monsterchomp. So, Similar to what we did above, create a selection using the Rounded Rectangle tool (U) with a <strong>height of 165px and a </strong><strong>width of 560px </strong>and a <strong>corner radius of 10px. </strong>This time I&#8217;m using a light grey for the background colour. With the placeholder well, in place, go grab an image of an awesome looking monster. I&#8217;m using the Green monster from Chris Spooner&#8217;s Free Monster Vector pack which can be downloaded <a href="http://www.blog.spoongraphics.co.uk/freebies/free-cute-furry-monster-icons-for-mac-pc-and-web" target="_blank">here</a>.</p>
<p><img class="aligncenter size-full wp-image-5224" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/51.png" alt="" width="600" height="194" /></p>
<p>Grab the Rounded Rectangle tool (U) and make a similar selection as you have been doing (keeping the corner radius at 10px). This time fill it with white so that it stands out against the light grey and any text that we place inside will appear nice and crisp. Now we need to make this rounded rectangle into an actual speech bubble. Grab the Pen Tool (P) making sure that it&#8217;s on &#8216;Shape Layers&#8217; mode and create a shape with three points pointing towards the monster&#8217;s mouth. The shape is almost like a right-angled triangle, except without the right angle, duh.</p>
<p><img class="aligncenter size-full wp-image-5200" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/6.png" alt="" width="600" height="189" /></p>
<p>Using the Horizontal Type Tool (T), add some text inside the speech bubble. Again, I&#8217;m using Myriad Pro Bold Condensed. The text has to be easy to read because this is the main part of our email. It&#8217;s what we want the users attention drawn too. After you&#8217;ve wrote a message, place some &#8216;legal text&#8217; underneath the speech bubble using a clear sans-serif font with a font size of 11px.</p>
<h3>6. &#8220;How do I claim my free Monsterchomp bar?&#8221;</h3>
<p>Now that the user has seen that they are entitled to a free bar of Monsterchomp they want to know <em>how</em> they can claim it. The main content area will be 2-columns. On the left <strong>(395px)</strong> we&#8217;ll have the instructions that tells the user how they can claim their free bar and on the right <strong>(155px)</strong> we&#8217;ll just put some Promotional Terms and Conditions <em>(yer, moar legal stuff).</em></p>
<p><em><img class="aligncenter size-full wp-image-5201" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/7.png" alt="" width="600" height="367" /><span style="font-style: normal;">Create a title for the content in a large font, keeping it crisp. I&#8217;m using Arial for all the email content (I like to keep font faces to a minimum in newsletters). Then add some instructions that clearly tells the user how they can claim their free bar.</span></em></p>
<p><em><span style="font-style: normal;"><img class="aligncenter size-full wp-image-5202" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/8.png" alt="" width="600" height="368" /></span></em></p>
<p>Create another Rounded Rectangle (U) selection on the right hand side and fill it with a light grey. Inside here you want to put Terms and Conditions of entry. Well, you don&#8217;t <em>have</em> to, I&#8217;m just doing this to give you an idea of how to design a 2-column newsletter.</p>
<h3>7. Submitting their entry</h3>
<p><img class="aligncenter size-full wp-image-5203" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/9.png" alt="" width="600" height="132" /></p>
<p>Keeping usability in mind for newsletters, we want to keep things simple. So, once the reader has done what they were supposed to they should be able to submit their entry easily without any fuss.</p>
<p>Again, using the Rounded Rectangle Tool (U) create a large selection, filling it with a nice light grey. We want to make this a button for the user to click on <em>(keeping usability in mind). </em>So, using Myriad Pro Bold Condensed <em>(again&#8230;)</em>, Type a message in the box to tell the reader that this is a button and should be clicked once all instructions are completed. To make the text stand out the bit further, Duplicate the Layer, change the text colour to white, position it below the main Text layer, move it 1px down and 1px right and then reduce the opacity until you&#8217;re comfortable with the outcome.</p>
<h3>8. Giving the readers more</h3>
<p><img class="aligncenter size-full wp-image-5204" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/10.png" alt="" width="600" height="124" />Sometimes freebies aren&#8217;t enough in this world and the readers will want more. So, offer an incentive for the user to enter.</p>
<h3>9. Giving the reader the ability to un-subscribe from the mailing list</h3>
<p><img class="aligncenter size-full wp-image-5205" src="http://www.tuttoaster.com/wp-content/uploads/2010/06/11.png" alt="" width="600" height="75" />Every newsletter needs to have a link or a button to allow the reader to freely un-subscribe from the newsletter. So, write a message at the bottom with a link to allow the user to un-subscibe.</p>
<h2>Conclusion</h2>
<p>Here&#8217;s what we&#8217;ve designed in this tutorial:</p>
<p><img src="http://www.tuttoaster.com/wp-content/uploads/2010/06/tutorial.jpg" alt="" width="600" height="880" /></p>
<p>Stay tuned and  <a title="Subscribe to our RSS-feed" rel="external nofollow" href="http://feeds.feedburner.com/Tuttoaster"><strong>subscribe to our RSS-feed</strong></a> or <a title="Follow us on Twitter" rel="external nofollow" href="http://twitter.com/TutToaster"><strong>follow us on Twitter</strong></a> because next time we&#8217;ll be learning how to code the design into a functional HTML newsletter ready for delivery!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/design-an-email-newsletter-in-photoshop-2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Creating Bar Graphs using jQuery UI</title>
		<link>http://www.tuttoaster.com/creating-bar-graphs-using-jquery-ui/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-bar-graphs-using-jquery-ui</link>
		<comments>http://www.tuttoaster.com/creating-bar-graphs-using-jquery-ui/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 15:26:17 +0000</pubDate>
		<dc:creator>Abhin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery ui]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://www.tuttoaster.com/?p=5726</guid>
		<description><![CDATA[In this tutorial we are going to leverage the power of jQuery UI and create a slick bar graph. So lets get started !! Setting up workspace - This tutorial already assumes you know jQuery and basics of jQuery UI. First goto jQuery UI website and download your copy of jQuery. Feel free to download [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we are going to leverage the power of jQuery UI and create a slick bar graph. So lets get started !!</p>
<h3>Setting up workspace -</h3>
<p>This tutorial already assumes you know jQuery and basics of jQuery UI. First goto <a href="http://jqueryui.com/">jQuery UI website</a> and download your copy of jQuery. Feel free to download any theme you like.</p>
<ul>
<li>Now import jquery and jquery-ui.custom.min.js in your html file, available in the js folder of the download.</li>
<li>Now goto css folder and link the jquery-ui-1.8.2.custom.css file in your project.</li>
<li>Finally create graph.js file in which we will code our bar graphs and import the script in our html page.</li>
</ul>
<p>So far our code looks like -<span id="more-5726"></span></p>
<pre class="brush: xml; title: ; notranslate">
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/custom-theme/jquery-ui-1.8.2.custom.css&quot; /&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.8.2.custom.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/graph.js&quot;&gt;&lt;/script&gt;
</pre>
<h3>Step 1</h3>
<p>Now either we can create a jQueryUI plugin or a jQuery one. For this tutorial, we will create a jQuery one. Before that open up jquery-ui-1.8.2.custom.css and the following code. The below will be the styling for our graph&#8217;s background and bar graph&#8217;s bar property.</p>
<pre class="brush: css; title: ; notranslate">
.ui-widget-bg { border-top: 1px dotted #aed0ea; font-size:9px;   }
.ui-widget-bar {position:absolute;zIndex:10;bottom:0;font-size:10px; }
</pre>
<h3>Step 2</h3>
<p>Now we will create a div that will be our graph and add some basic styling to the html file.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/custom-theme/jquery-ui-1.8.2.custom.css&quot; /&gt;
 &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-ui-1.8.2.custom.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/graph.js&quot;&gt;&lt;/script&gt;

&lt;title&gt;CSS Graphs&lt;/title&gt;
&lt;style&gt;
#container { width:960px; margin-left:auto; margin-right:auto; margin-top:100px;  }
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;div id=&quot;container&quot;&gt;
&lt;div id=&quot;graph&quot;&gt;

&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;
</pre>
<h3>Step 3</h3>
<p>Now we will code our jQuery plugin. First of all we will create the basic structure and add options.</p>
<pre class="brush: jscript; title: ; notranslate">
$.fn.graph = function(options){
	var defaults = {height:300,width:500,data:'',categories:'',legend:&quot;Graph&quot;};
	var options = $.extend(defaults, options);

    }
</pre>
<p>Our options will consists of -</p>
<ul>
<li>height &#8211; the height of the graph.</li>
<li>width &#8211; the width of the graph.</li>
<li>data &#8211; the values of the bars.</li>
<li>categories &#8211; categories or labels of the data.</li>
<li>legend &#8211; Heading of the graph</li>
</ul>
<h3>Step 4</h3>
<p>Now we are going to create the widget of the graph. In jQuery UI high level widgets uses ui-widget class. The main parent consist of ui-widget class which gives a consistent UI to all it&#8217;s nodes. We will not add ui-widget class to the main element that is calling the pluign but we will wrap the calling element into a div with class ui-widget.</p>
<pre class="brush: jscript; title: ; notranslate">
var root = $(this).addClass(&quot;ui-widget-content&quot;);
root.wrap(&quot;&lt;div class=' ui-widget ' /&gt;&quot;);
var parent = root.parent();
</pre>
<p>Since root is where actual graph will be, we will add ui-widget-content to it and wrap it in a div.</p>
<h3>Step 5</h3>
<p>Now we are going to set the properties of the graph from the options we have provided plus some of our own.</p>
<pre class="brush: jscript; title: ; notranslate">
parent.prepend(&quot;&lt;h3 class='ui-helper-reset ui-widget-header '&gt;&quot;+options.legend+&quot;&lt;/h3&gt;&quot;);
parent.css({height:options.height,width:options.width});
root.css(&quot;position&quot;,&quot;relative&quot;);
</pre>
<p>We will first add the heading to our graph from the option provided in a h3 tag which has a ui-helper-reset class which is a mini reset class for elements provided by jQuery UI,then we will add the widget header class. After that we will set the dimensions of root&#8217;s parent and set it&#8217;s position to relative.</p>
<blockquote><p>Reason of setting position relative is so that absolute positioned elements which we will be using later can adjust themselves with respect to the parent, if its not given to relative the bars will be all over the page <img src='http://www.tuttoaster.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .</p></blockquote>
<h3>Step 6</h3>
<p>Now we are going to declare variables that we are going to use later and lastly we will select the maximum value available in the data, since that will be our highest scale.</p>
<pre class="brush: jscript; title: ; notranslate">
var i=0,max_val=0,scale,datalen=0,temp,w;

	for(i=0;i&lt;options.data.length;i++)
	{
		if(options.data[i]&gt;=max_val)
		max_val = options.data[i];
	}
</pre>
<h3>Step 7</h3>
<p>Now we will create a scale. For that we will divide the graph into equal parts, by dividing it&#8217;s height by data length. Then we will initialize i variable with height for later use. Then we are going to create two div elements. One will be the graph background and other will be bars of the graph.</p>
<pre class="brush: jscript; title: ; notranslate">
scale = options.height/options.data.length;
	i=options.height;
	var bg = jQuery(&quot;&lt;div /&gt;&quot;,{ css:{height:scale - 1 }  }).addClass(&quot;ui-helper-reset ui-widget-bg&quot;);
    var bar = jQuery(&quot;&lt;div /&gt;&quot;,{ css:{width:width}  }).addClass(&quot;ui-helper-reset ui-state-active bar&quot;);
	var width = Math.floor((options.width-70)/options.data.length - (options.categories.length/1.5));
</pre>
<p>In the bg element we have added the ui-widget-bg class that we had manually created in the css file. Note that here height is scale -1, -1 is added because we have added a 1px solid top border. If we had not added the border, scaling would be disturbed. For the bar elements we have added active state class and a bar class that we will later use in events.</p>
<h3>Step 8</h3>
<p>Now we are going to add the gridlines to our graph. For that we will add bg elements to our graph that have equal height. We will also add per unit values in it. The values will be in respect to the original values that we have supplied not the scaled values.</p>
<pre class="brush: jscript; title: ; notranslate">
var counter = 0;

	while(i&gt;=0)
	{
		temp = bg.clone().html(max_val - counter);
		root.append(temp);
		i = i - scale;
		counter = counter + max_val/8;
		datalen++;
	}
</pre>
<p>So far our progress looks like -</p>
<div><img src="/wp-content/uploads/2010/06/1.jpg" alt="pic1" /></div>
<h3>Step 9</h3>
<p>Now we will add bar graphs, first of all we will loop all the values then we will calculate the height of the bar graph on our scale. Then we will add the bar with the calculated height and distance from the orgin with label as html.</p>
<pre class="brush: jscript; title: ; notranslate">
w= 40;

	 for(i=0;i&lt;options.categories.length;i++)
	   {

		temp =  Math.floor(options.data[i]/max_val * datalen * scale ) - scale;
		root.append(bar.clone().css({height:temp,left:w}).html(options.categories[i]));

		w = w + width + 10;

	  }
</pre>
<p>Now our graph looks like -</p>
<div><img src="/wp-content/uploads/2010/06/2.jpg" alt="pic2" /></div>
<h3>Step 10</h3>
<p>Finally we will add hover event for the bars , with some effects. When mouse hovers on a bar, other bars gets ui-priority-secondary class which reducts its opacity with respect to the hovered bar. Also we will add ui-state-hover on hovered bar.</p>
<pre class="brush: jscript; title: ; notranslate">
$(&quot;.ui-widget-bg:last&quot;).css(&quot;height&quot;,0);
	$(&quot;.bar&quot;).hover(function(){

					   $(this).toggleClass('ui-state-active ui-state-hover');
					   $(&quot;.bar&quot;).not(this).addClass('ui-priority-secondary');

					   },function(){

						   $(this).toggleClass('ui-state-active  ui-state-hover');
						$(&quot;.bar&quot;).not(this).removeClass('ui-priority-secondary');
						   });
</pre>
<h3>Step 11 &#8211; Calling the plugin</h3>
<p>Now comes the easy part, just call the plugin in the html we had imported our scripts earlier thats it !!</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
		   var d = [34,23,12,45,67,34,78,44];
		   var c = [&quot;January&quot;,&quot;Febuary&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;];
		   $(&quot;#graph&quot;).graph({data:d,categories:c,legend:&quot;This is a test&quot;});

		   });

&lt;/script&gt;
</pre>
<p>When you&#8217;ve got any questions regarding this tutorial, please don&#8217;t hesitate to ask. And when you enjoyed this tutorial, then we would appreciate it when you could spread the word about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tuttoaster.com/creating-bar-graphs-using-jquery-ui/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

