<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Cash &#187; html</title>
	<atom:link href="http://www.earn-web-cash.com/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Marking Up and Styling an Image Gallery</title>
		<link>http://www.earn-web-cash.com/2008/03/25/semantic-markup-image-album/</link>
		<comments>http://www.earn-web-cash.com/2008/03/25/semantic-markup-image-album/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 00:32:36 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[Markup]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/25/marking-up-and-styling-an-image-gallery/</guid>
		<description><![CDATA[While working on a new site (Rolling Horde), I decided to include a small image gallery. I randomly display four images from a flickr album in the sidebar. The pictures are presented in the mark-up that flickr creates, and I used the styling that came with the template I was working from. It creates a [...]]]></description>
			<content:encoded><![CDATA[<p>While working on a new site (<a href="http://rolling-horde.net">Rolling Horde</a>), I decided to include a small image gallery.  I randomly display four images from a flickr album in the sidebar.</p>
<p>The pictures are presented in the mark-up that flickr creates, and I used the styling that came with the template I was working from.  It creates a simple two by two square of photos, with a slight gap in between them.</p>
<p>Although I like the way they are presented, I&#8217;m not sure I like the mark-up that flickr creates.  What would be the simplest, semantic way to mark-up and style images in a small album like this?<br />
<span id="more-181"></span></p>
<h4>Semantic Mark-up: An Unordered List</h4>
<p>Flickr places all of the photos in divs.  These are then styled to float next to each other or appear however you like.</p>
<p>In my opinion, the most semantic way to mark-up photos like this would be to create an unordered list.  A photo album is essentially a list of photos.</p>
<p>This could be an ordered list if the photos were intended to be sequential &#8211; like a photo essay or a comic book &#8211; but the average photo album is just a collection of pictures.</p>
<p>The mark-up would look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>The images would then be displayed in a long, vertical list.</p>
<h4>Styling &#8211; Making the List Inline</h4>
<p>In the end, we&#8217;d like to have the images sit side by side.  Ideally, they&#8217;d form a rectangle of either 2 x 3 pictures, or 3 x 2.</p>
<p>The first thing we want to do, then, is remove the list style type, clear the padding/margins of the list, and make the images appear next to each other.  The last bit we can achieve by giving the list items the &#8220;display: inline&#8221; css declaration.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#images</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#images</span> li <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This would create a simple horizontal list, like this&#8230;</p>
<ul id="images_one">
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
</ul>
<h4>Width: Restricting the Number of Columns</h4>
<p>Notice how the list terminates at the end of its container div and continues on a second line?  </p>
<p>Without a width declaration, the unordered list expands as large as wide as it can.  When that width limit is hit, it starts a second line, and continues until all of the list items have been displayed.</p>
<p>We can use this to our advantage by setting a width declaration.  This allows us to limit the number of images to be displayed in each row.</p>
<p>If our images are 75px square, and we want to display three images across, we can set our width to be about 250px.  The extra space can be used later for paddings and margins &#8211; but the images will appear left justified within the list container.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#images</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">list-style-type</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#images</span> li <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This would create a list like this&#8230;</p>
<ul id="images_two">
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
</ul>
<h4>Finishing Touches: Padding and Borders</h4>
<p>With the basic structure complete, we can add a few finishing touches.</p>
<p>First, we might we to add a little padding to the images.  This would space them out a few pixels from each other so that they don&#8217;t appear so cramped.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#image</span> img <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Adding this line to the css file would change the image album to this.</p>
<ul id="images_three">
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
</ul>
<p>Finally, a cool effect for images is to add a border around the image.  If you include a padding value for the img tag, the border is placed 2-3 pixels away from the edge of the picture.  It gives a nice framing effect.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#image</span> img <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">thin</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This final change would look something like this.</p>
<ul id="images_four">
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
<li><img src="http://farm4.static.flickr.com/3047/2362739858_c82b4de7c2_s.jpg" /></li>
</ul>
<p>By using an unordered list to mark-up your image collection, you end up with semantically correct and simple to style content.  Much better, in my opinion, than a string of divs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/25/semantic-markup-image-album/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Five Useful, Simple WordPress Plugins</title>
		<link>http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/</link>
		<comments>http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 00:30:13 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Sundry Musings]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/</guid>
		<description><![CDATA[I&#8217;ve been playing around with developing WordPress sites for a while now. I love how quick and easy it is to launch a site and update content. One of the greatest features is the thousands of plug-ins available for WordPress. You can find a plug-in for just about anything you want to do &#8211; or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with developing WordPress sites for a while now.  I love how quick and easy it is to launch a site and update content.</p>
<p>One of the greatest features is the thousands of plug-ins available for WordPress.  You can find a plug-in for just about anything you want to do &#8211; or if you have some PHP know-how, you can develop your own.</p>
<p>Here are five basic WordPress plug-ins that I&#8217;d recommend using for <strong>any</strong> project you start.<br />
<span id="more-179"></span></p>
<h4>Akismet &#8211; Spam Protection</h4>
<p>This plug-in comes pre-installed with WordPress &#8211; and there&#8217;s absolutely no reason you shouldn&#8217;t use it.  <a href="http://akismet.com/>Akismet</a> automatically captures most spam comments and places them in a separate &#8220;spam&#8221; category.  You don&#8217;t get bombarded with &#8220;Moderate Now&#8221; e-mails, and you can trust that your comment logs will be pretty clean.</p>
<p>Since I&#8217;ve been using it on this site (about two months), Akismet has caught a little over 900 comments.  Once a week or so, I scan through the comment log and rescue any false positives.  Occasionally a legitimate comment will get swept up, but all you need to do is select it, hit &#8220;De-spam Comment,&#8221; and it will be saved.</p>
<h4>All In One SEO Plug-In</h4>
<p>The <a href="http://wp.uberdose.com/2007/03/24/all-in-one-seo-pack/">All In One SEO Plug-In</a> is just what it sounds like.  It adds some extra functionality to tweak the SEO of each of your posts and pages.</p>
<p>For example, All In One will automatically generate a description meta tag based on your excerpt and it will automatically generate keywords based on your tags.  You can also use this to modify the title element of each page.  I&#8217;d say it&#8217;s a must have for optimizing your website.</p>
<h4>Exec-PHP</h4>
<p>Early on, I was looking for a way to execute PHP code inside a post.  WordPress doesn&#8217;t have built-in support for this, so you need to find a plug in to do it.</p>
<p>There are dozens of plug-ins that attempted to implement this feature.  <a href="http://bluesome.net/post/2005/08/18/50/">Exec PHP</a> is hands down the best that I&#8217;ve found.  You simply add regular PHP tags to your post and the PHP code will be executed properly.  I&#8217;ve never run into any bugs while using the plug-in, unlike some other plug-ins I&#8217;ve tested.</p>
<h4>Per Post CSS and JS</h4>
<p><a href="http://www.flog.co.nz/">Per Post CSS and JS</a> allows you to attach individual stylesheets or javascript files to your posts or pages.  This is great for changing the look of a specific page without creating an entirely new template.  By attaching these files to individual posts, you cut down a lot on redundancy.</p>
<p>For example, let&#8217;s say you wrote a javascript file that you use in 10% of your posts.  Why should it be attached to the other 90% of your posts?</p>
<p>I&#8217;ve also found it <strong>very</strong> useful for creating HTML/CSS/JS tutorials.  I can place my sample code in external .css and .js files and have it attached properly to the page.  This way I don&#8217;t have to write in-line styles to demonstrate functionality.</p>
<h4>WP Unformatted</h4>
<p>This simple plug-in removes all of the auto-formatting that WordPress adds to your posts.  With <a href="http://alexking.org/projects/wordpress">WP Unformatted</a>, you can add a custom field to your post to tell the plug-in to strip out all of that formatting.</p>
<p>For example, WordPress likes to wrap text in <code>&lt;p&gt;</code> tags.  Sometimes &#8211; like with forms &#8211; this is entirely undesirable.  It can mess up your carefully formatted (and syntactically correct) HTML.</p>
<p>By using WP Unformatted, you can add sophisticated mark up to your post content without worrying that WordPress will screw it up with random <code>&lt;p&gt;</code> and <code>&lt;br /&gt;</code> tags.</p>
<h4>And Many More&#8230;</h4>
<p>There are, of course, dozens of other useful plug-ins.  I&#8217;ve used plenty of other plug-ins that I liked.  However, these are the ones that I feel appeal to the widest audience.</p>
<p>No matter what you&#8217;re doing, you&#8217;ll probably find a use for spam filtering, individualized stylesheets, SEO, PHP, and clean formatting.  I would never start another project without these plug-ins.</p>
<p>What else do you find useful?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/20/useful-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Flash Movies: Standards Compliant Embedding</title>
		<link>http://www.earn-web-cash.com/2008/03/18/flash-movies-standards-compliant-embedding/</link>
		<comments>http://www.earn-web-cash.com/2008/03/18/flash-movies-standards-compliant-embedding/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 22:27:13 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/18/flash-movies-standards-compliant-embedding/</guid>
		<description><![CDATA[The other day, I was looking into using Picasa to create an image album and embed it as a slideshow on a website. Uploading the images and creating the album was easy. However, I noticed that the code Google creates to embed the slideshow (a flash file) is not standards compliant &#8211; it uses the [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I was looking into using Picasa to create an image album and embed it as a slideshow on a website.</p>
<p>Uploading the images and creating the album was easy.  However, I noticed that the code Google creates to embed the slideshow (a flash file) is not standards compliant &#8211; it uses the <code>&lt;embed&gt;</code> tag.</p>
<p>How can we convert this code to a standards compliant version?<br />
<span id="more-178"></span></p>
<h4>The Original Picasa Embed Code</h4>
<p>The code that Google generates to embed the flash file uses the embed element.  The embed tag includes all of the pertinent information &#8211; the swf file, the height, the width, and the parameters.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;embed <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://picasaweb.google.com/s/c/bin/slideshow.swf&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;288&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;192&quot;</span></span>
<span style="color: #009900;">  flashvars<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;host=picasaweb.google.com&amp;RGB=0x000000&amp;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fslowwalkere%2Falbumid%2F5178325186511467969%3Fkind%3Dphoto%26alt%3Drss&quot;</span></span>
<span style="color: #009900;">  pluginspage<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.macromedia.com/go/getflashplayer&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>embed&gt;</span></pre></div></div>

<p>The problem here is that the code uses the embed tag.  This is no longer recognized as a valid html element &#8211; although it still functions in most browsers.</p>
<h4>Converting Embed to Object</h4>
<p>We can, however, convert this embed element into an object element.  The object element <strong>is</strong> standards compliant, and <a href="http://www.alistapart.com/articles/flashsatay">with a few parameters</a> it is compatible across most browsers.</p>
<p>To do this, let&#8217;s identify the information that we&#8217;ll need from the original Picasa code.</p>
<p>Obviously, we&#8217;ll need the flash file.  This is the value of the &#8220;src=&#8221; attribute.  We&#8217;ll also need the height and width, which are pretty obvious.  Finally, we&#8217;ll need the parameters to be passed to the flash movie &#8211; located in the flashvars parameter.</p>
<p>Here&#8217;s what an object element might look like to display a flash movie.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flash-file.swf&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flash-file.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span></pre></div></div>

<p>We create the object and give it the attribute <code>type="application/x-shockwave-flash"</code>.  This tells the browser it is a flash movie.</p>
<p>We pass the name of the flash file with the data attribute and the &#8220;movie&#8221; param element &#8211; notice that the filename is passed twice here.</p>
<p>Finally, we pass the height and width parameters as attributes to the object element.</p>
<h4>Filling Out the Object</h4>
<p>Now we can take the values provided for us by Google and create a new, valid object to display the flash slideshow.</p>
<p>The only extra thing we need to know is that we can send another param element &#8211; name=&#8221;flashVars&#8221; &#8211; to contain the flash parameters.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://picasaweb.google.com/s/c/bin/slideshow.swf&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;288&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;192&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://picasaweb.google.com/s/c/bin/slideshow.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flashVars&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;host=picasaweb.google.com&amp;amp;RGB=0x000000&amp;amp;feed=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fslowwalkere%2Falbumid%2F5178325186511467969%3Fkind%3Dphoto%26alt%3Drss&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span></pre></div></div>

<p>This should do the trick and display our Flash slideshow in a standards compliant way.  You should also be able to apply this to any other widget that displays a flash movie.</p>
<p>Also, here are two minor things to keep in mind.</p>
<p>The param elements are self closing &#8211; i.e. <code>&lt;param /&gt;</code>.  The param element doesn&#8217;t contain any text, so it must be self closing to be standards compliant.</p>
<p>The flashVars value is constructed as a query string.  It utilizes ampersands (&amp;) to separate key/value pairs.  Ampersands are a standards no-no &#8211; they should be escaped as an html entity (<code>&amp;amp;</code>).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/18/flash-movies-standards-compliant-embedding/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Anatomy of a WordPress Template: The Basics</title>
		<link>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/</link>
		<comments>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 23:46:12 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/</guid>
		<description><![CDATA[There are tons of free WordPress templates available, but at some point you&#8217;ll probably want to modify one or make your own. Even if you know HTML pretty well, this can be a daunting task at first. WordPress templates have a decent amount of simple PHP mixed in, and you need to utilize a special [...]]]></description>
			<content:encoded><![CDATA[<p>There are tons of free WordPress templates available, but at some point you&#8217;ll probably want to modify one or make your own.  Even if you know HTML pretty well, this can be a daunting task at first.</p>
<p>WordPress templates have a decent amount of simple PHP mixed in, and you need to utilize a special file structure for the template to operate correctly.  Before you dive into making a WordPress template, let&#8217;s look at the basic structure of a WordPress template compared to a normal website template.<br />
<span id="more-175"></span></p>
<h4>Example Basic Website Template</h4>
<p>A typical website consists of a few parts &#8211; the content, a header, and a footer.  You may also have a sidebar for navigation and/or a horizontal menu bar.  The typical markup for this type of template would look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;</span>
  ...  Header Stuff Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
  ...  Main Content Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebar&quot;</span>&gt;</span>
  ...  This floats to a side ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;footer&quot;</span>&gt;</span>
  ...  Footer Stuff Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>If you&#8217;ve learned some PHP, then you can include a series of PHP files to create your webpage template.  Chances are your header, footer, and sidebar are the same for all or most of your pages &#8211; so it makes sense to create them one time each.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'header.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
  ...  Main Content Here ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sidebar.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'footer.php'</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span></pre></div></div>

<p>Nothing too complicated here.  Just a simple, barebones template.</p>
<h4>What Does a WordPress Template File Look Like?</h4>
<p>Although the terminology is a bit different, a WordPress template has the same basic structure.  Let&#8217;s look at a pared down version of the default template&#8217;s index.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php get_header<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;narrowcolumn&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;?php if <span style="color: #66cc66;">&#40;</span>have_posts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : ?&gt;</span>
    <span style="color: #009900;">&lt;?php while <span style="color: #66cc66;">&#40;</span>have_posts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : the_post<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post-&lt;?php the_ID(); ?&gt;</span></span>&quot;&gt;
      ... Post Info ...
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;?php endwhile; ?&gt;</span>
  <span style="color: #009900;">&lt;?php endif; ?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php get_sidebar<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;?php get_footer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span></pre></div></div>

<p>The bulk of the action here is in the &#8220;content&#8221; div.  With PHP, WordPress checks to see if any posts were retrieved from the database.  If they are, then it loops through the posts and outputs each one.</p>
<p>&#8220;Post Info&#8221; would be replaced by the markup you want to use for the actual post headings, information, and content.</p>
<p>The PHP function calls are similar to the include() calls in the earlier template.  get_header() fetches the standard header info, get_sidebar() fetches the sidebar, and get_footer() fetches the footer.  But where does WordPress find this information?</p>
<h4>Special WordPress Template Files</h4>
<p>WordPress uses some standard tempalte files to make these functions work.</p>
<p>For example, get_header() looks for the header.php file.  It&#8217;s more or less a proxy call for include(&#8216;header.php&#8217;).  To make WordPress work properly, therefore, you should include all of your header information in header.php.</p>
<p>The same goes for get_footer() and footer.php as well as get_sidebar() and sidebar.php.</p>
<p>So, to begin designing a WordPress template or to convert a regular website template to a WordPress template, you need to worry about four basic files:</p>
<ul>
<li>header.php &#8211; the header div and information</li>
<li>footer.php &#8211; the footer div and information</li>
<li>sidebar.php &#8211; the sidebar div and information</li>
<li>index.php &#8211; calls get_header(), get_footer(), and get_sidebar(), and contains the content div</li>
</ul>
<p>There are some other special files as well, but this is enough to get started.  Once you understand the basic structure of the template, you can look into customizing the information that is displayed for each post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/03/10/wordpress-template-basics/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Spoof a Form, or Why Your Form Isn&#8217;t Safe</title>
		<link>http://www.earn-web-cash.com/2008/02/25/spoof-forms-security/</link>
		<comments>http://www.earn-web-cash.com/2008/02/25/spoof-forms-security/#comments</comments>
		<pubDate>Tue, 26 Feb 2008 00:54:03 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[spoof]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/25/spoof-forms-security/</guid>
		<description><![CDATA[Forms can create all kinds of security holes in PHP applications. The biggest reason for this is that you can never be sure just what kind of input you&#8217;ll be getting. There are some steps you can take later on to protect your applications from this unknown input. But first, let&#8217;s take a look at [...]]]></description>
			<content:encoded><![CDATA[<p>Forms can create all kinds of security holes in PHP applications.  The biggest reason for this is that you can never be sure just what kind of input you&#8217;ll be getting.</p>
<p>There are some steps you can take later on to protect your applications from this unknown input.  But first, let&#8217;s take a look at <strong>why</strong> you can never trust a user&#8217;s input and just how easy it is for someone to spoof a form.<br />
<span id="more-160"></span></p>
<h4>What Does It Mean to Spoof a Form?</h4>
<p>It could mean a number of related things, but generally speaking it means submitting form information in a manner other than the original form was intended.  The form processing script, completely unaware of the situation, processes the input as if it came from the original form.</p>
<p>For example, if a form generates a URL query string, one way to spoof that form would be to modify the query string and re-visit the URL.  The new page would think that my query came from the original form &#8211; even though I really crafted the query myself.</p>
<p>Why would someone want to do this?  It may be curiosity.  &#8220;I wonder what happens if I change this variable&#8230;&#8221;  Or it may be malicious.  A hacker can spoof a form processing script to send dangerous input to your PHP script.</p>
<h4>The Problem With the &#8220;Get&#8221; Method</h4>
<p>It is easiest to spoof a form if the information is transmitted through the &#8220;Get&#8221; method.  This means that the variables are placed into a query string and appended to the form&#8217;s action URL.</p>
<p>Let&#8217;s say you have a form with three elements &#8211; a textarea element, a hidden input, and a select element.  Logically, you might think that the hidden input is restricted to whatever value you set it to and the select element is restricted to one of the options you provided.</p>
<p>To make this a little more concrete, let&#8217;s assume the textarea contains a post to a multi-user blog, the hidden input contains the author&#8217;s name, and the select element includes the category number.</p>
<p>When the user enters the values and clicks &#8220;submit,&#8221; he&#8217;s sent to a URL that looks something like this.</p>
<pre>processing.php?text=Bla+bla+bla&#038;author=Walkere&#038;catid=2</pre>
<p>What if I wanted to pretend to be someone else &#8211; like Bob?  I could simply change the &#8216;author&#8217; variable.</p>
<pre>processing.php?text=Bla+bla+bla&#038;author=Bob&#038;catid=2</pre>
<p>Maybe I want to post my message in a special category &#8211; one that isn&#8217;t normally open to me.  Again, it&#8217;s as simple as changing the catid variable to another number.</p>
<p>Now, a well designed script will notice these data flukes and either ignore them or spit out an error.  However, if you have too much faith in form input &#8211; and you blindly used the values from your form &#8211; you&#8217;d soon be in a mess of trouble.</p>
<h4>But Post Is More Secure&#8230; Right?</h4>
<p>The &#8220;Post&#8221; method is somewhat more secure.  Why?  Because all of the information is transmitted behind the scenes.</p>
<p>When I was younger, I tried to meddle with the $_GET variables of an online game that I played.  I never would have known enough about the workings of the script to spoof a &#8220;post&#8221; form &#8211; but it was so blatantly obvious with &#8220;get.&#8221;</p>
<p>However, someone &#8220;in the know&#8221; can easily spoof a form using the post method as well.  One way to do this is&#8230; write your own form.</p>
<p>If I look at the HTML source of your form, I can easily see what values you&#8217;re submitting to the processing script.  I can recreate those input elements on a form on <strong>my</strong> site &#8211; and then set the action to your processing script.</p>
<p>In this way, I could make the hidden and select statements regular text inputs &#8211; and input whatever values I want.  If you&#8217;re form processing script isn&#8217;t savvy, my custom values will get passed on to the database.</p>
<p>One thing you can do to prevent this is to check the referring URL coming into your script.  This will prevent someone from simply creating a form off-site to spoof your script.</p>
<h4>Sending an Actual HTTP Request</h4>
<p>The final, and most devious way, to spoof a form is to craft your own HTTP request in PHP.  This is essentially what a form does &#8211; but you can manually craft the request to your liking instead of letting a form do it.</p>
<p>How do we do this?</p>
<p>First, we create a stream context.  To do that we create a simple array and then call the function stream_context_create.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'http'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'method'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'http'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'headers'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Referer: http://www.google.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'http'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// A regular query string with parameters</span>
&nbsp;
<span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$processingUrl</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fpassthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The actual form values are placed in the $data variable.  This is in a typical query string format &#8211; key=var&#038;key2=var2, etc.  The values should also be url encoded.</p>
<p>The nifty thing here is that you can manually specify HTTP headers to be sent with your request.  In this example, we set the referring URL to Google.  If someone knew your processing script checked the referrer&#8217;s address &#8211; they could simply spoof it with an HTTP header.</p>
<h4>Never Trust Input</h4>
<p>The bottom line is &#8211; never trust input that you haven&#8217;t thoroughly tested, validated, and cleaned.</p>
<p>Even if an input item is supposed to be hidden or supposed to come from a specific set of values &#8211; you can&#8217;t be sure that the form processing script is going to receive the correct value.  The script needs to check the info and make sure that it got what it was looking for.</p>
<p>It&#8217;s pretty simple for someone to spoof your form and send any input they like to your processing script.  If you don&#8217;t close the security holes, then someone will eventually blow them open for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/25/spoof-forms-security/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JS Game: Making a Real Game Board from a Concept</title>
		<link>http://www.earn-web-cash.com/2008/02/20/js-game-board-complete/</link>
		<comments>http://www.earn-web-cash.com/2008/02/20/js-game-board-complete/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 04:08:57 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[JS Tutorials]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/20/js-game-board-complete/</guid>
		<description><![CDATA[In a recent post, I sketched out how to use Javascript to build a gameboard for a browser-based game &#8211; specifically Tic Tac Toe. After a little tweaking, I&#8217;ve worked this into a functioning Tic Tac Toe board. In this post, we&#8217;ll explore the code used to set up this board. Once that&#8217;s done, the [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent post, I sketched out how to <a href="http://www.earn-web-cash.com/2008/02/19/js-online-game-board/">use Javascript to build a gameboard for a browser-based game</a> &#8211; specifically Tic Tac Toe.  After a little tweaking, I&#8217;ve worked this into a functioning Tic Tac Toe board.</p>
<p>In this post, we&#8217;ll explore the code used to set up this board.  Once that&#8217;s done, the next step will be to create a php script to evaluate some of the game&#8217;s logic.<br />
<span id="more-136"></span></p>
<h5>Recap: The Game Board Concept</h5>
<p>First, let&#8217;s take a step back and recap our Javascript game board concept.</p>
<p>The basic building block of our game board is a div element.  This div element is styled with a CSS stylesheet &#8211; 50px by 50px.  By using floats and clearss strategically, we can stack 9 of these div elements into a 3&#215;3 box.</p>
<p>Javascript is added to make these boxes functional.  An &#8220;onClick&#8221; handler is used to call a Javascript function that changes the background image of the div.  This effectively marks the square as either a &#8220;Circle&#8221; or &#8220;Cross&#8221; for Tic Tac Toe.</p>
<p>To alter the div &#8211; and also to add textual output &#8211; we&#8217;ll be using Javascript&#8217;s powerful DOM functions.  These allow us to grab a specific element by it&#8217;s ID and change it.</p>
<h5>Creating Graphics</h5>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcircle.png' title='Tic Tac Toe Circle Image'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcircle.png' alt='Tic Tac Toe Circle Image' /></a>I created two images in Inkscape to use for this board.  Each is a 50&#215;50 png file &#8211; with a gray background and a black border.  The actual token (the circle or cross) is red and laid on top of the gray background.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcross.png' title='Tic Tac Toe Cross Image'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcross.png' alt='Tic Tac Toe Cross Image' /></a>I&#8217;m no great artist, but these should work for a functional demo.  We can worry about making nice circle and cross tokens later.  I think getting the game <strong>working</strong> is more important than making it pretty from the get-go.</p>
<h5>Turning Our .js Script into a Class</h5>
<p>In making this a functional board, I also converted the script into an actual class.  The script may end up being somewhat large and unwieldy &#8211; and an object oriented approach may help us keep it tidy and clean.  Or it may add a lot of overhead&#8230; but I like objects.</p>
<p>In our HTML file, we&#8217;ll create the object like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
var tictactoe = new game();
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>In the attached .js file, we actually define the <strong>game</strong> object.  Here&#8217;s part of the object definition.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> game<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">//  Array to hold the bgImgs</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bgImgs</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bgImgs</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'tttcircle.png'</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bgImgs</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'tttcross.png'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">//  Player information			</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">players</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">players</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Player One&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">players</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Player Two&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>This class constructor does some of the initialization for us.</p>
<p>First, it creates an array with background images.  At the moment we&#8217;re only using two images.  However, this technique would be useful if you had a more complex map &#8211; with 10-15 images you could lay over a div.</p>
<p>Second, we create some player information variables.  The &#8216;currentPlayer&#8217; property is going to track whether the &#8216;cross&#8217; or &#8216;circle&#8217; player is currently taking a turn.  The &#8216;players&#8217; array will just hold the names of those players for now.</p>
<h5>The Background Image Changing Function</h5>
<p>One of the major methods of this class will be changeBackground().  Just like in the previous example, this method will change the background style of a given div tag.  This way we can change it from an open square to a circle or cross token.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">changeBackground</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>boxId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> box <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'box-'</span> <span style="color: #339933;">+</span> boxId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    box.<span style="color: #660066;">style</span>.<span style="color: #660066;">background</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'transparent url('</span> <span style="color: #339933;">+</span> 
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bgImgs</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">') top left no-repeat'</span><span style="color: #339933;">;</span>
&nbsp;
    box.<span style="color: #660066;">removeAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'onClick'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">changePlayer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This should be pretty straightforward.  We&#8217;re storing the &#8216;div&#8217; element in the &#8216;box&#8217; variable.  We&#8217;re then setting the &#8216;background&#8217; style as we would in a css style.  Remember that we stored the background images in an array (this.bgImgs) and this.currentPlayer corresponds to a key in the this.bgImgs array (either 0 or 1).</p>
<p>The &#8216;box.removeAttribute()&#8217; method is removing &#8216;onClick&#8217; from that div.  We can&#8217;t use a square a second time, so we might as well eliminate the onClick handler altogether.</p>
<p>Finally, this.changePlayer() is calling a new method.  This is going to help us switch from Player One&#8217;s turn to Player Two&#8217;s turn.</p>
<h5>One Turn to Another &#8211; this.changePlayer()</h5>
<p>The last method we need to declare for this class at the moment is changePlayer.</p>
<p>This will toggle the active player &#8211; which in turn affects whether a circle or cross is placed on the board.  For some added effect, we&#8217;ll also create a new html element to display a message that says who&#8217;s turn it is.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">changePlayer</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//  Switch the active player</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//  Get a reference to our 'message' element and create the message</span>
    <span style="color: #003366; font-weight: bold;">var</span> box <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;It is &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">players</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">currentPlayer</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'s turn.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> txt <span style="color: #339933;">=</span> document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//  Erase any existing text</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>box.<span style="color: #660066;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      box.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>box.<span style="color: #660066;">lastChild</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//  Add the text node (our message) to our element</span>
    box.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>txt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Again, this is pretty straightforward.  The DOM functions are amazingly simple &#8211; once you see how they work.</p>
<p>&#8216;box&#8217; is a reference to our element (id = message).  The msg variable is a temp variable I created to hold the string.  The &#8216;createTextNode&#8217; method creates a new block of text (with our msg) that we can then insert into an HTML element.</p>
<p>The while() loop is simply there to erase any old text.  As long as our &#8216;box&#8217; element has any child nodes inside of it (text or other HTML tags), the loop will execute and delete one of those child nodes each time.  This way we have a clean slate on which to write down who&#8217;s turn it is.</p>
<p><script type="text/javascript">var tictactoe = new game();</script></p>
<p style="float: left; margin-right: 1em;" class="message break" id="message">
<div class="break">
<div class="box" id="box-1" onClick="tictactoe.changeBackground('1');">1</div>
<div class="box" id="box-2" onClick="tictactoe.changeBackground('2');">2</div>
<div class="box" id="box-3" onClick="tictactoe.changeBackground('3');" style="margin-right: 1em;">3</div>
</div>
<div class="break">
<div class="box" id="box-4" onClick="tictactoe.changeBackground('4');">4</div>
<div class="box" id="box-5" onClick="tictactoe.changeBackground('5');">5</div>
<div class="box" id="box-6" onClick="tictactoe.changeBackground('6');" style="margin-right: 1em;">6</div>
</div>
<div class="break">
<div class="box" id="box-7" onClick="tictactoe.changeBackground('7');">7</div>
<div class="box" id="box-8" onClick="tictactoe.changeBackground('8');">8</div>
<div class="box" id="box-9" onClick="tictactoe.changeBackground('9');" style="margin-right: 1em;">9</div>
</div>
<h5>Seeing It In Action</h5>
<p>Well, that&#8217;s really all there is to it.  Have a look at this functioning demo.  If you had trouble piecing together the example code, you can download the source files (.js, .css, and two .png) from the list below.</p>
<p>Good luck, and be sure to check back soon.  Our next task is going to be a <strong>real</strong> challenge.  We need to add some <strong>logic</strong> to this game &#8211; evaluating victoary conditions and creating AI!</p>
<p>Source code files:</p>
<ul>
<li><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tictactoe-basic.js' title='Basic Tic-Tac-Toe JS File'>Basic Tic-Tac-Toe JS File</a></li>
<li><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tictactoe1.css' title='Tic-Tac-Toe CSS File (#2)'>Tic-Tac-Toe CSS File (#2)</a></li>
<li><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcross.png' title='Tic Tac Toe Cross Image'>Tic Tac Toe Cross Image</a></li>
<li><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/tttcircle.png' title='Tic Tac Toe Circle Image'>Tic Tac Toe Circle Image</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/20/js-game-board-complete/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Alternate CSS Styles Using PHP</title>
		<link>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/</link>
		<comments>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 04:08:08 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/13/how-to-alternate-css-styles-using-php/</guid>
		<description><![CDATA[There are a lot of situations in which you'd like to alternate CSS styles from one element to the next.  Long tables, for example, look a lot nicer when the background color of the rows is alternated (think: Gmail).

How do we do that?  Some pretty simple PHP can help you accomplish this task and spice up your HTML/CSS.]]></description>
			<content:encoded><![CDATA[<p>There are a lot of situations in which you&#8217;d like to alternate CSS styles from one element to the next.  Long tables, for example, look a lot nicer when the background color of the rows is alternated.</p>
<p>How do we do that?  Some pretty simple PHP can help you accomplish this task and spice up your HTML/CSS.<br />
<span id="more-111"></span></p>
<h5>Look At the HTML/CSS</h5>
<p>Before we start making things dynamic, let&#8217;s look at the basic HTML.</p>
<p>Let&#8217;s say we want to make a list of items &#8211; in a table &#8211; maybe a list of emails.  The end result should be a table with alternating background colors for rows &#8211; white and light blue.</p>
<p>If we were to create this table by hand, it might look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;blue&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>E-mail subject<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Sender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;white&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>E-mail subject<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Sender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p>This assumes that we have a CSS class defined as &#8220;blue&#8221; with a blue background and &#8220;white&#8221; with a white background.</p>
<h5>Adding Some PHP to Assign Classes</h5>
<p>We&#8217;re setting the background color by adding a class declaration to the table row.  The first step in making this dynamic is to use PHP to echo the class.  Like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo 'blue'; ?&gt;</span></span>&quot;&gt;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span> ... <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span></pre></div></div>

<p>We&#8217;ve taken the same table row element from before and replaced &#8220;blue&#8221; with a php snippet that echos the same phrase, &#8220;blue.&#8221;  The end result is the same HTML that we created in the first example.</p>
<h5>Dynamically Choosing the Class</h5>
<p>The final step in making this dynamic is to add a conditional statement to the PHP block.  For example, let&#8217;s say we&#8217;re executing a loop 5 times.  On the odd iterations (1, 3, 5) we&#8217;ll use &#8220;blue&#8221; as the class.  On the even iterations (2, 4), we&#8217;ll use &#8220;white.&#8221;</p>
<p>To test whether or not a number is odd, you can use the modulus (%) operator.  This returns the remainder of a division &#8211; so <code>2 % 3 = 1</code>.  With a little basic math theory, we know that if a number is divided by 2 and has no remainder it&#8217;s even &#8211; but if there&#8217;s a remainder of 1 it&#8217;s odd.</p>
<p>Here&#8217;s what the loop might look like.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;blue&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;white&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;td&gt; ... &lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h5>That If Statement Is Kind of Long&#8230;</h5>
<p>Well, we can shorten that up.  This is a great place to use the obscure and un-readable ternary operator in PHP.  It&#8217;s a shortcut that allows you to write a simple if-statement in one line.</p>
<p>For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span> ? <span style="color: #0000ff;">&quot;Yes&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;No&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The ternary operator takes three parts &#8211; the conditional statement (in this case I just wrote true), a value to return if the statement is true (&#8220;Yes&#8221;), and a value to return if the statement is false (&#8220;No&#8221;).  I echo&#8217;ed the result just so you could see what the statement outputs (in this case, &#8220;Yes&#8221;).</p>
<p>We turn our previous if statement into a ternary operator statement and shorten up that code block quite a bit.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span> ? <span style="color: #0000ff;">&quot;blue&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;white&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;td&gt; ... &lt;/td&gt;&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Creating these table rows is just one example of how you can use PHP to help spice up your HTML.  With this concept, you can dynamically alternate styles based on a bunch of factors.</p>
<p>How else could you use this?</p>
<p>You could alternate the background colors of comments in your blog template.  You could include a bottom-border after every five rows in your table.  You could make a calendar module and display Saturday and Sunday in boldface.</p>
<p>The options are really endless &#8211; so long as you understand the basic principal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/13/alternate-css-styles-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Use Attribute Selectors to Fine Tune Your CSS</title>
		<link>http://www.earn-web-cash.com/2008/01/31/css-attribute-selectors/</link>
		<comments>http://www.earn-web-cash.com/2008/01/31/css-attribute-selectors/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 00:28:01 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[anchor]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/31/css-attribute-selectors/</guid>
		<description><![CDATA[Here's a quick tip for fine tuning your CSS declarations.  

You can use attribute selectors to style an html element that contains an attribute with the value that you declare.  This allows you to do a bunch of cool stuff - like style different "input" types differently, style anchor tags with titles differently, and et]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tip for fine tuning your CSS declarations.  </p>
<p>You can use attribute selectors to style an html element that contains an attribute with the value that you declare.  This allows you to do a bunch of cool stuff &#8211; like style different &#8220;input&#8221; types differently, style anchor tags with titles differently, and etc.<br />
<span id="more-89"></span><br />
How does it work?</p>
<p>An attribute selector follows this basic formula&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">&#91;</span>attribute<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;value&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> style information... <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Like an id or class selector, you can use it alone (as in the example above), or attach it to a specific html element.</p>
<p>How can we use it?  Here are a few examples.</p>
<h5>Style Links with Title Elements Differently</h5>
<p>You could use this to give users a hint that an anchor tag or link has a title element.  This way they know to hover over the link and read the tooltip.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #00AA00;">&#91;</span>title<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">thin</span> <span style="color: #993333;">dotted</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>That declaration gives any anchor tag containing a &#8220;title&#8221; attribute a thin dotted blue underlining.  You may have to tweak it a bit to make sure the normal anchor-underlining doesn&#8217;t interfere with it.</p>
<h5>Style Particular Input Types on Forms</h5>
<p>You can use this to style Submit buttons, Text Inputs, etc. &#8211; independent of other input types.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span>  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This simple declaration gives all Submit buttons a blue background color.  Fairly silly, but the point is the declaration &#8211; not the actual styling.  You could do something similar with these declarations&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">input <span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #808080; font-style: italic;">/* style information */</span> <span style="color: #00AA00;">&#125;</span>
input <span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;password&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #808080; font-style: italic;">/* style information */</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<h5>Style Internal Links Different from External Links</h5>
<p>This is a really nifty trick&#8230; but unfortunately it requires a bit of CSS 3.  This will probably invalidate your CSS, and your mileage may vary.</p>
<p>It&#8217;s still interesting to try out.</p>
<p>You can use &#8220;^=&#8221; instead of &#8220;=&#8221; to signal that the browser should match any element with the given attribute that contains the quoted string.  It doesn&#8217;t have to be an exact match.  So you can use &#8220;^=&#8217;mydomain.com&#8217;&#8221; to match any links that point to the domain you&#8217;re working on.</p>
<p>Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #00AA00;">&#91;</span>href<span style="color: #00AA00;">^=</span><span style="color: #ff0000;">&quot;earn-web-cash.com&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #808080; font-style: italic;">/* style information */</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You could use this to given internal links a slightly different color &#8211; some kind of queue to help the user differentiate between internal and external links.</p>
<p>For a longer list of ways to use this neat little trick, check out this post <a href="http://www.search-this.com/2007/11/14/hip-to-be-square/" title="Uses for CSS Attribute Selectors">Hip to Be Square</a>.  There&#8217;s also a list of the different ways to search for values (like ^=) &#8211; which will be valid in CSS 3.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/31/css-attribute-selectors/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Use PHP To Dynamically Resize an Image</title>
		<link>http://www.earn-web-cash.com/2008/01/30/resize-images-php/</link>
		<comments>http://www.earn-web-cash.com/2008/01/30/resize-images-php/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 01:26:57 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/30/resize-images-php/</guid>
		<description><![CDATA[One of the most annoying things about working with images is getting them into the right size. Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website. Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right. What if [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' title='Screenshot of a Dzone Page'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.thumbnail.png' alt='Screenshot of a Dzone Page' /></a>One of the most annoying things about working with images is getting them into the right size.  Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website.</p>
<p>Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right.  What if you want the image a different size, though?  You could allow the browser to resize it for you, or &#8211; better yet &#8211; write your own php script to resize the image dynamically.<br />
<span id="more-87"></span></p>
<h5>Why You Shouldn&#8217;t Let the Browser Resize Images</h5>
<p><img src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' class='alignright' style='width: 200px; height: 150px'; />Look at the original picture &#8211; the small thumbnail created by WordPress.  Notice how large it is &#8211; 13.9kb.  When WordPress resizes the image, it also reduces the file size.  If I were to include the fullsize image and resize it using css height and width attributes, the file size would <strong>not</strong> be cut down.  </p>
<p>Want proof?  Look at the second image to the right &#8211; that&#8217;s simply resized by the browser.  It&#8217;s a whopping 284.21kb.</p>
<p><img src='/scripts/resize-image.php?image=http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' class='alignright' />If we write our own php script to resize the image dynamically, we can control both the image size <strong>and</strong> the file size.  Check out the third image to the right &#8211; which was resized with a php script.  You&#8217;ll notice that it looks nicer too &#8211; the browser isn&#8217;t designed to resize images.</p>
<h5>Using the PHP GD Library to Resize the Image</h5>
<p>So how do we do this?  We&#8217;re going to make use of the PHP GD library to manipulate the image, and a $_GET parameter to tell it which image to re-size.</p>
<p>Let&#8217;s walk through using the GD library to re-size an image.  Then we&#8217;ll see how to include that in your HTML to actually do the resizing for you.</p>
<p>First, we need to open up the original file and get it&#8217;s size and type characteristics.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$src_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$srcsize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>imagecreatfrompng()</code> creates an image object and stores it in $src_image.  If the file was a different type we could replace &#8220;png&#8221; with &#8220;jpeg&#8221; or &#8220;gif.&#8221;  <code>getimagesize()</code> stores an array in $srcsize that contains the width of the image ($srcsize[0]), the height of the image ($srcsize[1]), and the filetype of the image ($srcsize[2]).</p>
<p>Now we need to create new dimensions for the new image and actually create an image.  We&#8217;ll resize it to 200 pixels wide &#8211; and then adjust the height to maintain the ratio.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dst_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The calculations should be self explanatory.  <code>imagecreatetruecolor()</code> creates a new image object for us with the given dimensions &#8211; which we will soon fill in with our resized image.</p>
<p>The next step is to place the resized image into <code>$dst_img</code> and output the image as Image content.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
    <span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>imagecopyresampled()</code> copies an image ($dst_img) into a new image ($src_img) with a set of given attributes (including our sizes).  The &#8220;Header&#8221; line tells the browser that this is an image &#8211; so that it&#8217;s not displayed as a bunch of gibberish.  Finally, the <code>imagepng()</code> function actually displays the image.</p>
<p>Now, we need to clean up and destroy the image objects.  Otherwise, we could end up sapping a lot of memory from the server.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Displaying the Script in HTML</h5>
<p>If you load the script directly, you should simply see the image.  It creates an image resource and displays it in the browser &#8211; as if &#8220;resize-image.php&#8221; was really &#8220;image.png.&#8221;</p>
<p>Therefore all we need to do to include this new image in an HTML page is use the php script as the <code>src</code> attribute of our <code>&lt;img&gt;</code> tag.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'resize-image.php'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>The script will execute, create an image, and use that as the <code>src</code>.</p>
<p>The last thing we need to do is modify our script so that we can pass it some information.  </p>
<p>It wouldn&#8217;t do much good if we had to write a new php script for every image we wanted to resize.  Instead, we can use the $_GET array to send a variable (the image filename) to our image resizing script.</p>
<p>Here&#8217;s the entire image resizing script, with the $_GET variable used for the filename.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//  Create source image and dimensions</span>
<span style="color: #000088;">$src_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$srcsize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dst_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Resize image</span>
<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Output image</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Destroy images</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To use this, you need to slightly modify your HTML and add an &#8220;image&#8221; parameter to the URL of your script.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'resize-image.php?image=image.png'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>There ya go!  Now you can resize images on the fly.</p>
<h5>Next Steps to Take&#8230;</h5>
<p>This is of course a basic introduction to the topic.  You can add a lot of functionality to resize-image.php.</p>
<p>For example, you could take extra parameters &#8211; like a width and/or height.  You might also want to include a bunch of error checking &#8211; make sure the file exists, make sure the new dimensions are appropriate, etc.  </p>
<p>You could also use a <code>switch()</code> statement to open different types of images &#8211; based on the contents of $srcsize[2].  Remember, you can use the GD library to do more than work with .png files.  By replacing &#8216;png&#8217; with &#8216;jpeg&#8217; or &#8216;gif&#8217; you can use the same functions to work with these file types.  For example, <code>imagecreatefromjpeg</code> is equivalent to <code>imagecreatefrompng</code>.</p>
<p>In the near future, I plan on extending this example into a full-fledged script for immediate download and use.  So stay tuned &#8211; and leave any comments with suggestions for what the script should be able to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/30/resize-images-php/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>How to Pass All Elements of a Form to the End in a Multi-Page Form</title>
		<link>http://www.earn-web-cash.com/2008/01/27/multi-page-form/</link>
		<comments>http://www.earn-web-cash.com/2008/01/27/multi-page-form/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 22:44:29 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/27/how-to-pass-all-elements-of-a-form-to-the-end-in-a-multi-page-form/</guid>
		<description><![CDATA[Sometimes forms get long, unsightly, and intimidating.  It'd be great if you could cut them up into three or four parts - with a few fields on each page.

In order to do that, you need to figure out some way of storing or passing along the information from the first pages.  I've heard a bunch of crazy ideas - from storing the information in session variables to writing each part to the database.

The easiest thing to do is attach a <em>very</em> brief php function to the bottom of each page.  It'll do all the work for you and continue to post every item the user has entered.]]></description>
			<content:encoded><![CDATA[<p>Sometimes forms get long, unsightly, and intimidating.  It&#8217;d be great if you could cut them up into three or four parts &#8211; with a few fields on each page.</p>
<p>In order to do that, you need to figure out some way of storing or passing along the information from the first pages.  I&#8217;ve heard a bunch of crazy ideas &#8211; from storing the information in session variables to writing each part to the database.</p>
<p>The easiest thing to do is attach a <em>very</em> brief php function to the bottom of each page.  It&#8217;ll do all the work for you and continue to post every item the user has entered.<span id="more-77"></span></p>
<p>To start with, let&#8217;s create a hypothetical page one of a form.  This will give us something to work with for the rest of this tutorial.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;script.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lastname&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;poneSubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Continue&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>Here we&#8217;ve got three form elements &#8211; although only two of them really count.  When we get to the second page, we need to make sure that &#8220;firstname&#8221; and &#8220;lastname&#8221; are passed along so that the final processing page can store the data appropriately.</p>
<p>When the second page (&#8220;script.php&#8221;) loads, these values will be stored in <code>$_POST['firstname']</code> and <code>$_POST['secondname']</code>.</p>
<p>Every value in a form that is submitted with <code>method="post"</code> ends up in the superglobal array <code>$_POST</code> with a key equal to its <code>name</code> attribute in the form.</p>
<p>In order to continue to pass these values along and make them accessible through the <code>$_POST</code> superglobal on other pages, we can use a simple foreach loop.  With each iteration of the loop, we&#8217;ll create a new <code>&lt;input type="hidden" /&gt;</code> to store the information.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> 
    <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will cycle through the <code>$_POST</code> array and create all of the hidden elements for us.  So we&#8217;d end up with this being added to our next page in the form.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'firstname'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Bob'</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'lastname'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Stevenson'</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'poneSubmit'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Continue'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>All you need to do is add that snippet of php to the end of your form on each subsequent(after page one), and all of the values will end up in the <code>$_POST</code> array at the end.  [Note:  Make sure this is <strong>inside</strong> the form tags, or else it won't get passed along.]</p>
<p>If you want to take it one step further, you can standardize this into a neat little function.  Then include this function in your common includes file, and you can use it on any page with a simple function call.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> passArray<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> 
      <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s all there is to it!  Go write up some forms.</p>
<p>[Note:  If you're wondering why the <code>"\r\n"</code> is there, it's just to make the source code look nicer.  It adds a newline so that your source code is nice and spread out.  Otherwise, every element our function adds would be on the same line - making the source code pretty illegible.]</p>
<p><strong>Update.</strong>  It&#8217;s been pointed out to me that there&#8217;s a possible security hole in this method.  No big deal.  This article that revisits <a href="http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/">multi-page forms</a> patches the hole up nice and snug.  I&#8217;d suggest you take a look at it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/27/multi-page-form/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

