<?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>ElbertF Blog</title>
	<atom:link href="http://elbertf.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://elbertf.com/wp</link>
	<description>Insights and Updates from a Tech Geek</description>
	<lastBuildDate>Mon, 01 Mar 2010 10:26:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to store passwords safely with PHP and MySQL</title>
		<link>http://elbertf.com/wp/2010/01/store-passwords-safely-with-php-and-mysql/</link>
		<comments>http://elbertf.com/wp/2010/01/store-passwords-safely-with-php-and-mysql/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 08:43:27 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=447</guid>
		<description><![CDATA[First, let me tell you how not to store passwords and&#160;why.
Do not store password as plain&#160;text
This should be obvious. If someone gains access to your database then all user accounts are compromised. And not only that, people tend to use the same password on different sites so those accounts will be compromised as well. Your [...]]]></description>
			<content:encoded><![CDATA[<p>First, let me tell you how <strong>not</strong> to store passwords and&nbsp;why.</p>
<h4>Do not store password as plain&nbsp;text</h4>
<p>This should be obvious. If someone gains access to your database then all user accounts are compromised. And not only that, people tend to use the same password on different sites so those accounts will be compromised as well. Your site doesn&#8217;t even need to be hacked; a system administrator could easily browse your&nbsp;database.</p>
<h4>Do not try to invent your own password&nbsp;security</h4>
<p>Chances are that you&#8217;re no security expert. You&#8217;re better off using a solution that has been proven to work instead of coming up with something&nbsp;yourself.</p>
<h4>Do not encrypt&nbsp;passwords</h4>
<p><a href="http://en.wikipedia.org/wiki/Encryption">Encryption</a> may seem like a good idea but the process is reversible. Anyone with access to your code would have no trouble transforming the passwords back to their originals. <a href="http://en.wikipedia.org/wiki/Security_through_obscurity">Security through obscurity</a> is not&nbsp;sufficient!</p>
<p><span id="more-447"></span></p>
<h4>Do not use&nbsp;MD5</h4>
<p>Storing password <a href="http://en.wikipedia.org/wiki/Hash_function">hashes</a> is a step in the right direction. Cryptographic hashing functions like <a href="http://en.wikipedia.org/wiki/MD5">MD5</a> are irreversible which makes it difficult to figure out the original password. To validate a hashed password, simply hash the password again when a user logs in and compare the&nbsp;hashes.</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;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'swordfish'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Value: 15b29ffdce66e10527a65bc6d71ad94d</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Note that this makes it impossible to retrieve a password from the database. If a user forgets his password, simply generate a new&nbsp;one.</p>
<p>So why not MD5? It is quite easy to make a list of millions of hashed passwords (a <a href="http://en.wikipedia.org/wiki/Rainbow_table">rainbow table</a>) and compare the hashes to find the original passwords (the same goes for other hashing functions like&nbsp;<a href="http://en.wikipedia.org/wiki/SHA_hash_functions">SHA-1</a>).</p>
<p>MD5 is also prone to <a href="http://en.wikipedia.org/wiki/Brute_force_attack">brute forcing</a> (trying out all combinations with an automated script) because of <a href="http://en.wikipedia.org/wiki/Collision_resistance">collisions</a>. This means that different passwords can have the same hash, making it even easier to find one that&nbsp;works.</p>
<p>MD5 collision demo:&nbsp;<a href="http://www.mscs.dal.ca/~selinger/md5collision/">mscs.dal.ca/~selinger/md5collision</a></p>
<h4>Do not use a single site-wide&nbsp;salt</h4>
<p>A <a href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29">salt</a> is a string that is hashed together with a password so that most rainbow tables (or <a href="http://en.wikipedia.org/wiki/Dictionary_attack">dictionary attacks</a>) won&#8217;t&nbsp;work.</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;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'swordfish'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'something random'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$salt</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Value: db4968a3db5f6ed2f60073c747bb4fb5</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is better then using just MD5 but someone with access to your code can find the salt a generate a new rainbow&nbsp;table.</p>
<h4>What you should&nbsp;do</h4>
<ul>
<li>Use a cryptographically strong hashing function like SHA-1 or even SHA-256 (see PHP&#8217;s <a href="http://www.php.net/manual/en/function.hash.php">hash()</a>&nbsp;function).</li>
<li>Use a long and random salt for each&nbsp;password.</li>
<li>Use a slow hashing algorithm to make brute force attacks near&nbsp;impossible.</li>
<li>Regenerate the hash every time a users logs&nbsp;in.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gf45_gdf#4hg'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create a 256 bit (64 characters) long random salt</span>
<span style="color: #666666; font-style: italic;">// Let's add 'something random' and the username</span>
<span style="color: #666666; font-style: italic;">// to the salt as well for added security</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sha256'</span><span style="color: #339933;">,</span> <span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'something random'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Prefix the password with the salt</span>
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$salt</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Hash the salted password a bunch of times</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> <span style="color: #cc66cc;">100000</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: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sha256'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Prefix the hash with the salt so we can find it back later</span>
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$salt</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hash</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Value:
 * e31f453ab964ec17e1e68faacbb64f05bccceb179858b4c482c1b182ff1e440e
 * f1e10feb5b86c6d367e4eb8f90f2cde5648a7db3df8526878f20a77eed00c703
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In the above example we turned a reasonably strong password into a 128 characters long hash that we can store in a database. The next time the user logs in we can validate the password as&nbsp;follows:</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;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'gf45_gdf#4hg'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'
    SELECT
        `hash`
    FROM `users`
        WHERE `username` = &quot;'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;
    LIMIT 1
    ;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The first 64 characters of the hash is the salt</span>
<span style="color: #000088;">$salt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hash'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">64</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$salt</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Hash the password as we did before</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> <span style="color: #cc66cc;">100000</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: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sha256'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$salt</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hash</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$hash</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'hash'</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;">// Ok!</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>A few additional tips to prevent user accounts from being&nbsp;hacked:</p>
<ul>
<li>Limit the number of failed login&nbsp;attempts.</li>
<li>Require strong&nbsp;passwords.</li>
<li>Do not limit passwords to a certain length (remember, you&#8217;re only storing a hash so length doesn&#8217;t&nbsp;matter).</li>
<li>Allow special characters in passwords, there is no reason not&nbsp;to.</li>
</ul>
<p>That&#8217;s it, happy&nbsp;coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2010/01/store-passwords-safely-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Swiftlet 1.1 Stable</title>
		<link>http://elbertf.com/wp/2010/01/swiftlet-1-1-stable/</link>
		<comments>http://elbertf.com/wp/2010/01/swiftlet-1-1-stable/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 04:36:28 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=418</guid>
		<description><![CDATA[I released a new stable version of Swiftlet a few days ago together with a new web page at swiftlet.org. Swiftlet is a light-weight framework written in PHP aimed to make website development faster and&#160;easier.
Version 1.1 comes with a few new plugins that bring CMS-like features to Swiftlet. See the changelog for the full list [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/>I released a new stable version of Swiftlet a few days ago together with a new web page at <a href="http://swiftlet.org/">swiftlet.org</a>. Swiftlet is a light-weight framework written in PHP aimed to make website development faster and&nbsp;easier.</p>
<p>Version 1.1 comes with a few new plugins that bring CMS-like features to Swiftlet. See the <a href="http://code.google.com/p/swiftlet/source/browse/trunk/CHANGELOG">changelog</a> for the full list of&nbsp;changes.</p>
<p>The documentation has also been updated and can now be found at <a href="http://swiftlet.org/docs/?intro">swiftlet.org/docs</a>. If you need support or have any requests, feel free to start a thread at&nbsp;<a href="http://swiftlet.org/community/">swiftlet.org/community</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2010/01/swiftlet-1-1-stable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safer web forms with security tokens</title>
		<link>http://elbertf.com/wp/2009/11/safer-web-forms-with-security-tokens/</link>
		<comments>http://elbertf.com/wp/2009/11/safer-web-forms-with-security-tokens/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 08:24:31 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=367</guid>
		<description><![CDATA[
A common issue with many web applications is their vulnerability for Cross-Site Request Forgery, or XSRF. It allows a hacker to send a malicious request to a website with an other user&#8217;s privileges. Here&#8217;s how it&#160;works:



A hacker creates a page with a form that submits data to&#160;example.com.


An administrator from example.com is tricked into visiting the [...]]]></description>
			<content:encoded><![CDATA[<p>
A common issue with many web applications is their vulnerability for <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-Site Request Forgery</a>, or XSRF. It allows a hacker to send a malicious request to a website with an other user&#8217;s privileges. Here&#8217;s how it&nbsp;works:
</p>
<ul>
<li>
A hacker creates a page with a form that submits data to&nbsp;<em>example.com</em>.
</li>
<li>
An administrator from <em>example.com</em> is tricked into visiting the page, the form is submitted using&nbsp;JavaScript.
</li>
<li>
The data is handled by <em>example.com</em> as if it came from the administrator (because it&nbsp;did).
</li>
</ul>
<p>
This allows a hacker to perform administrative tasks on <em>example.com</em> like editing pages or deleting&nbsp;users.
</p>
<p><span id="more-367"></span></p>
<h4>Solution</h4>
<p>
Probably the best solution to this problem is using a <a href="http://en.wikipedia.org/wiki/Security_token">security token</a>. This is a code (usually a <a href="http://en.wikipedia.org/wiki/Hash_function">hash</a>) that is send with the form in a hidden field and is only valid for a specific user and a certain period of&nbsp;time.
</p>
<p>
I recommend using a <a href="http://en.wikipedia.org/wiki/SHA_hash_functions">SHA1</a> hash created from these&nbsp;components:
</p>
<ul>
<li>
Information about the user (IP address, user agent,&nbsp;username).
</li>
<li>
Information about the server (hostname, software&nbsp;version).
</li>
<li>
Information about the website (database name, table&nbsp;prefix).
</li>
<li>
Information that expires (user&#8217;s session&nbsp;id).
</li>
</ul>
<p>
This will result in an unpredictable and seemingly random hash that is still verifiable by the server and difficult to&nbsp;fake.
</p>
<p>
After the form is submitted the hash is re-created and compared to the token that was send with the form. Only if the hashes match the form is processed, otherwise an error message is displayed. This way even if a hacker manages to find the user&#8217;s token the request will&nbsp;fail.
</p>
<p><strong>Example&nbsp;(PHP/HTML):</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$authToken</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">session_id</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
  <span style="color: #990000;">phpversion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
  <span style="color: #000088;">$dbName</span> <span style="color: #339933;">.</span>
  <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span>
  <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'auth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'auth_token'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$authToken</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Process form</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;">// Display error message</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
&lt;form id=&quot;form&quot; method=&quot;post&quot; action=&quot;./&quot;&gt;
  &lt;fieldset&gt;
    &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
    &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; value=&quot;&quot;/&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;auth_token&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$authToken</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt;
&nbsp;
    &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
  &lt;/fieldset&gt;
&lt;/form&gt;</pre></div></div>

<p>Note that this only really works for POST requests. For this reason GET (regular links) should never be used to pass information that is used for administrative tasks. AJAX requests should also <em>always</em> use&nbsp;POST.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/11/safer-web-forms-with-security-tokens/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using Internet Explorer 8 for IE6 and IE7 testing</title>
		<link>http://elbertf.com/wp/2009/10/using-internet-explorer-8-for-ie6-and-ie7-testing/</link>
		<comments>http://elbertf.com/wp/2009/10/using-internet-explorer-8-for-ie6-and-ie7-testing/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 23:06:54 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=342</guid>
		<description><![CDATA[I personally don&#8217;t care what my websites look like in IE6 or 7 (or 8) but for those who do there is neat little trick to test your site for these&#160;browsers.
The hard&#160;way
If you&#8217;re on Windows XP or older you can use a standalone version of IE6. If you&#8217;re on Windows 7 (not the beta though), [...]]]></description>
			<content:encoded><![CDATA[<p>I personally don&#8217;t care what my websites <a href="http://elbertf.com/ie6ify">look like in IE6</a> or 7 (or 8<!---->) but for those who do there is neat little trick to test your site for these&nbsp;browsers.</p>
<h4>The hard&nbsp;way</h4>
<p>If you&#8217;re on Windows XP or older you can use a <a href="http://tredosoft.com/Multiple_IE">standalone version of IE6</a>. If you&#8217;re on Windows 7 (not the beta though), you can use Microsoft&#8217;s free &#8220;<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=21EABB90-958F-4B64-B5F1-73D0A413C8EF&#038;displaylang=en">IE Application Compatibility VPC Image</a>&#8221; to run XP with IE6 or 7 in a virtual machine. If you&#8217;re on any other operating system (Windows Vista, Mac OS, Linux) and have a Windows XP license you can run it using a VM like&nbsp;<a href="http://www.virtualbox.org/">VirtualBox</a>.</p>
<h4>The easy&nbsp;way</h4>
<p>If you&#8217;re already running IE8 there is an easier way. <a href="http://www.microsoft.com/windows/internet-explorer/features/easier.aspx">Compatibility View</a> will render pages as IE7, and a missing <a href="http://www.w3.org/QA/Tips/Doctype">doctype</a> will cause pages to be rendered as IE6 in <a href="http://en.wikipedia.org/wiki/Quirks_mode">quirks&nbsp;mode</a>.</p>
<p>You can simply remove the doctype from your pages when you&#8217;re testing for IE6 or ― if you&#8217;re using PHP ― add a simple&nbsp;switch:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ie6'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now you can simply add &#8220;?ie6&#8221; to the URL in IE8 to see what your page looks like in IE6. You can even keep several tabs open to make sure it works with all&nbsp;versions.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/10/using-internet-explorer-8-for-ie6-and-ie7-testing/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Swiftlet documentation update</title>
		<link>http://elbertf.com/wp/2009/07/swiftlet-documentation-update/</link>
		<comments>http://elbertf.com/wp/2009/07/swiftlet-documentation-update/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 22:41:47 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=334</guid>
		<description><![CDATA[The documentation for Swiftlet 1.0, a light-weight PHP framework I&#8217;ve been working on, is now pretty much&#160;complete.
I&#8217;ve already begun working on Swiftlet 1.1 which is now in Alpha (unstable and not suited for live&#160;environments).
]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/>The documentation for <a href="http://swiftlet.org">Swiftlet 1.0</a>, a light-weight PHP framework I&#8217;ve been working on, is now pretty much&nbsp;complete.</p>
<p>I&#8217;ve already begun working on Swiftlet 1.1 which is now in Alpha (unstable and not suited for live&nbsp;environments).</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/07/swiftlet-documentation-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated direct messages on Twitter</title>
		<link>http://elbertf.com/wp/2009/07/automated-direct-messages-on-twitter/</link>
		<comments>http://elbertf.com/wp/2009/07/automated-direct-messages-on-twitter/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 00:36:39 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[dm]]></category>
		<category><![CDATA[stopautodm]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=292</guid>
		<description><![CDATA[I&#8217;m a bit over the amount of spam I receive through Twitter&#8217;s messaging system. I get a fair number of direct messages every day and most of them are automated. I do read them all in case someone sends me a genuine&#160;message.
It shouldn&#8217;t be to hard for Twitter to detect automated messages, they could give [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a bit over the amount of spam I receive through Twitter&#8217;s messaging system. I get a fair number of direct messages every day and most of them are automated. I do read them all in case someone sends me a genuine&nbsp;message.</p>
<p>It shouldn&#8217;t be to hard for Twitter to detect automated messages, they could give me an option to block messages that have been send out more then ten times by a single user (I could create an application to do this myself but simply don&#8217;t have the bandwidth to handle that many messages, it would need thousands of active users to be&nbsp;effective).</p>
<p>Instead, I created a <a href="http://elbertf.com/stopautodm">Twitter app</a> to report users who send auto DMs to. Just tweet &#8220;@stopautodm @username&#8221; and they will be placed on the Hall of Shame. Perhaps at some point I could add an option to automatically unfollow the most reported&nbsp;users.</p>
<p>Website: <a href="http://elbertf.com/stopautodm">elbertf.com/stopautodm</a><br />
Twitter: @<a href="http://twitter.com/stopautodm">stopautodm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/07/automated-direct-messages-on-twitter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>IE6ify Bookmarklet</title>
		<link>http://elbertf.com/wp/2009/06/ie6ify-bookmarklet/</link>
		<comments>http://elbertf.com/wp/2009/06/ie6ify-bookmarklet/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 08:22:32 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[ie6ify]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=267</guid>
		<description><![CDATA[Today I created yet another utterly useless (but hopefully mildly entertaining) application;&#160;IE6ify.
It&#8217;s a bookmarklet that brings the joy of browsing the web with Microsoft Internet Explorer 6 to modern browsers. For almost a decade IE6 has managed to intrigue me by breaking standards-compliant websites in the most unpredictable ways. Whatever you did to fix a [...]]]></description>
			<content:encoded><![CDATA[<p>Today I created yet another utterly useless (but hopefully mildly entertaining) application;&nbsp;<a href="http://elbertf.com/ie6ify/">IE6ify</a>.</p>
<p>It&#8217;s a bookmarklet that brings the joy of browsing the web with <a href="http://en.wikipedia.org/wiki/IE6">Microsoft Internet Explorer 6</a> to modern browsers. For almost a decade IE6 has managed to intrigue me by breaking <a href="http://www.w3.org/">standards-compliant</a> websites in the most unpredictable ways. Whatever you did to fix a problem only made things worst, like an ugly dragon that grows two heads every time you cut one&nbsp;off.</p>
<p>Since it&#8217;s not possible to run IE6 natively on Windows Vista or 7 and IE6 in Linux Wine is a nightmare, I figured a lot of you would miss the old days. With IE6ify you can break any website in true IE6&nbsp;fashion.</p>
<p>Website:&nbsp;<a href="http://elbertf.com/ie6ify">elbertf.com/ie6ify</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/06/ie6ify-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JavaScript Tetris</title>
		<link>http://elbertf.com/wp/2009/06/javascript-tetris/</link>
		<comments>http://elbertf.com/wp/2009/06/javascript-tetris/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 02:11:08 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[tetris]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=246</guid>
		<description><![CDATA[Because I have nothing better to do with my time I wrote a Tetris game in JavaScript. I know there are plenty out there already but it was fun to make and it brought back some memories (I wrote my first Tetris game in DOS when I was 14). Coincidentally, Tetris just turned&#160;25.
I released it [...]]]></description>
			<content:encoded><![CDATA[<p>Because I have nothing better to do with my time I wrote a <a href="http://elbertf.com/tetris">Tetris game in JavaScript</a>. I know there are plenty out there already but it was fun to make and it brought back some memories (I wrote my first Tetris game in DOS when I was 14). Coincidentally, <a href="http://tetris.com">Tetris</a> just turned&nbsp;25.</p>
<p>I released it under <a href="http://opensource.org/licenses/gpl-3.0.html">GPL</a>, feel free to grab the code from the source and do whatever you like with&nbsp;it.</p>
<p>Play the game at&nbsp;<a href="http://elbertf.com/tetris">elbertf.com/tetris</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/06/javascript-tetris/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Object Oriented CSS</title>
		<link>http://elbertf.com/wp/2009/05/object-oriented-css/</link>
		<comments>http://elbertf.com/wp/2009/05/object-oriented-css/#comments</comments>
		<pubDate>Sat, 16 May 2009 03:56:20 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=186</guid>
		<description><![CDATA[Okay, there is no such thing as object oriented CSS. But there are advantages in OO programming that we can use in&#160;CSS.

p &#123;
    margin: 0;
&#125;
&#160;
#content p &#123;
    margin: 1em 0;
&#125;

In this example p would be a class and #content p would be an instance of that class. Let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, there is no such thing as object oriented CSS. But there are advantages in <a href="http://en.wikipedia.org/wiki/Object-oriented">OO programming</a> that we can use in&nbsp;CSS.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#content</span> p <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>In this example <code>p</code> would be a <em>class</em> and <code>#content p</code> would be an <em>instance</em> of that class. Let&#8217;s say the margin set in <code>p</code> is a <em>method</em> and we got the basic concepts of&nbsp;OOP.</p>
<p><span id="more-186"></span></p>
<h4>Practicle&nbsp;example</h4>
<p>A single HTML element can serve different purposes on a page. A list element for example can be used as a navigational menu (styled horizontally) and as a regular list in content (styled vertically). Sometimes it&#8217;s difficult to change one without changing the&nbsp;other.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #993333;">inside</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#menu</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#content</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* We only want bullets if a list appears in content */</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">outside</span> <span style="color: #993333;">disc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Here I created two <em>instances</em> of the <code>li</code> <em>object</em>. If you change either one it won&#8217;t effect the&nbsp;other.</p>
<h4>CSS&nbsp;Reset</h4>
<p>It&#8217;s useful to reset all style properties first using a CSS reset. In the above example I simply applied <code>list-style: none inside;</code> to the <code>li</code> element so you won&#8217;t see bullets (&bull;) unless you specify it. It&#8217;s easier to just reset everything at once, like&nbsp;this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</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;">1em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">'Trebuchet MS'</span><span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.4em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #993333;">inside</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Adding this code on top of your CSS file will give you full control over your&nbsp;code.</p>
<p>As a bonus this will probably solve a lot of your cross-browser compatibility problems. This is because every browser applies <a href="http://lists.w3.org/Archives/Public/www-style/2008Jul/att-0124/defaultstyles.htm">different default CSS</a> to&nbsp;elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/05/object-oriented-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Swiftlet 1.0.0 Stable</title>
		<link>http://elbertf.com/wp/2009/05/swiftlet-100-stable/</link>
		<comments>http://elbertf.com/wp/2009/05/swiftlet-100-stable/#comments</comments>
		<pubDate>Fri, 08 May 2009 02:51:32 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pintail]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=164</guid>
		<description><![CDATA[Swiftlet, the light-weight PHP framework that I&#8217;ve been working on for a while, is now&#160;stable.
Feature-wise not much has changed since the Beta and Release Candidate cycles but the code has been thoroughly tested and improved where possible. If you&#8217;re planning on building a PHP website, give Swiftlet a&#160;try.
I moved the project page and documentation away [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/><a href="http://swiftlet.org/">Swiftlet</a>, the light-weight PHP framework that I&#8217;ve been working on for a while, is now&nbsp;stable.</p>
<p>Feature-wise not much has changed since the Beta and Release Candidate cycles but the code has been thoroughly tested and improved where possible. If you&#8217;re planning on building a PHP website, <a href="http://code.google.com/p/swiftlet/downloads/list">give Swiftlet a&nbsp;try</a>.</p>
<p>I moved the project page and documentation away from Google Code, if you go to <a href="http://swiftlet.org/">swiftlet.org</a> you&#8217;ll find the new page. It&#8217;s powered by a documentation system that I custom coded (dubbed Pintail). If there is any interest I will release the code behind it as Open-Source as&nbsp;well.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/05/swiftlet-100-stable/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Swiftlet Beta</title>
		<link>http://elbertf.com/wp/2009/05/swiftlet-beta/</link>
		<comments>http://elbertf.com/wp/2009/05/swiftlet-beta/#comments</comments>
		<pubDate>Sat, 02 May 2009 08:17:52 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=156</guid>
		<description><![CDATA[Swiftlet is now in beta, after 15 alpha cycles I&#8217;m confident that it&#8217;s now pretty much feature complete (there core that is, there will be plenty more plug-ins) and relatively&#160;stable.
One of the most important recently added features is the plug-in installer. It checks for compatibility with the core code and creates and populates database tables [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/><a href="http://swiftlet.org">Swiftlet</a> is now in beta, after 15 alpha cycles I&#8217;m confident that it&#8217;s now pretty much feature complete (there core that is, there will be plenty more plug-ins) and relatively&nbsp;stable.</p>
<p>One of the most important recently added features is the plug-in installer. It checks for compatibility with the core code and creates and populates database tables with a click of the mouse. Plug-ins that don&#8217;t require a database connection don&#8217;t need to be installed; they&#8217;re <em>plug-and-play</em> (and Swiftlet runs fine without a&nbsp;database).</p>
<p>I also added plug-ins to handle user sessions and authorization. This should make it easy to create a website that requires a login&nbsp;system.</p>
<p>Download:&nbsp;<a href="http://code.google.com/p/swiftlet/downloads/list">code.google.com/p/swiftlet/downloads/list</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/05/swiftlet-beta/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Swiftlet — light-weight PHP framework</title>
		<link>http://elbertf.com/wp/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/</link>
		<comments>http://elbertf.com/wp/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 03:48:55 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[gpl]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[swiftlet]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=132</guid>
		<description><![CDATA[I just released an early alpha version of Swiftlet, an Open Source, light-weight PHP framework released under the GPL&#160;license.
It&#8217;s targeted at developers who want to built simple websites that don&#8217;t require large and complex frameworks, but do want a solid base to work from. Swiftlet provides basic security features such as user input sanitizing,  [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://code.google.com/p/swiftlet/logo?logo_id=1240554537" alt="Swiftlet logo" class="left"/>I just released an early alpha version of <a href="http://swiftlet.org">Swiftlet</a>, an Open Source, light-weight PHP framework released under the <a href="http://www.gnu.org/licenses/gpl.html">GPL&nbsp;license</a>.</p>
<p>It&#8217;s targeted at developers who want to built simple websites that don&#8217;t require large and complex frameworks, but do want a solid base to work from. Swiftlet provides basic security features such as user input sanitizing,  is highly extensible thanks to the deeply integrated hook system, completely Object Oriented and separates logic from design&nbsp;(MVC).</p>
<p>Even the most basic features such as connecting to a database and output buffering are implemented as plug-ins. This means they can be modified, extended and removed without hacking into the core&nbsp;code.</p>
<p>Website:&nbsp;<a href="http://swiftlet.org/">http://swiftlet.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/04/swiftlet-%e2%80%94-light-weight-php-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Twitchance winner announced</title>
		<link>http://elbertf.com/wp/2009/04/first-twitchance-winner-announced/</link>
		<comments>http://elbertf.com/wp/2009/04/first-twitchance-winner-announced/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 01:32:35 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[twitchance]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=96</guid>
		<description><![CDATA[I just announced the first winner on Twitchance: @benjaminluk gets the&#160;$500!
6S Marketing made a bold move supporting Twitchance by being the first sponsor. The concept was unproven and perhaps a bit controversial but they were curious and decided is was worth a try. I encourage you to follow them on&#160;Twitter.
The next draw is on April [...]]]></description>
			<content:encoded><![CDATA[<p>I just announced the first winner on <a href="http://twitchance.com">Twitchance</a>: @benjaminluk gets the&nbsp;$500!</p>
<p>6S Marketing made a bold move supporting Twitchance by being the first sponsor. The concept was unproven and perhaps a bit controversial but they were curious and decided is was worth a try. I encourage you to <a href="http://twitter.com/6s_marketing">follow them</a> on&nbsp;Twitter.</p>
<p>The next draw is on April 20, this time sponsored by <a href="http://hover.com">Hover</a> who provided another $500 and 20 smaller&nbsp;prizes.</p>
<p>We decided to make a small concept change: instead of <a href="http://elbertf.com/index.php/2009/03/twitchance">randomly selecting a winner</a> the sponsor and I pick the most creative message on Twitter and award the author with the&nbsp;prize.</p>
<p>To join, simply follow the instructions on the <a href="http://twitchance.com">Twitchance</a>&nbsp;website.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/04/first-twitchance-winner-announced/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: How not to pollute the global scope</title>
		<link>http://elbertf.com/wp/2009/03/php-how-not-to-pollute-the-global-scope/</link>
		<comments>http://elbertf.com/wp/2009/03/php-how-not-to-pollute-the-global-scope/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:04:27 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=62</guid>
		<description><![CDATA[An emerging trend in JavaScript is to wrap entire programs in a single object to prevent conflicts with other scripts. The same can be done with PHP, something I haven&#8217;t seen done very&#160;often.

If you ever want to combine frameworks you may discover that they use similar names for some variables and functions. This can lead [...]]]></description>
			<content:encoded><![CDATA[<p>An emerging trend in JavaScript is to wrap entire programs in a single object to prevent conflicts with other scripts. The same can be done with PHP, something I haven&#8217;t seen done very&nbsp;often.</p>
<p><span id="more-62"></span></p>
<p>If you ever want to combine frameworks you may discover that they use similar names for some variables and functions. This can lead to unexpected output and security holes. If you&#8217;re planning on writing a framework of your own, consider wrapping it in an&nbsp;object.</p>
<p>In PHP5 it&#8217;s possible to pass objects by reference which means you can send an instance of a class to another class. This way you can nest classes and access the&nbsp;parent.</p>
<p><strong>core.php:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> core
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>
        <span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a global variable.'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span>
        CONST_VAR <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This is a constant.'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// This function is executed when core is initialized.</span>
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classes/foo.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> foo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// All the main functions go here.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>foo.php:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> foo
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$core</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$core</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Reference to the core object.</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">core</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$core</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">function</span> hello_world<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this example &#8220;core&#8221; is the site&#8217;s main object containing global variables and functions. When we create an instance of class &#8220;foo&#8221;, we send a reference to the core object (&#8220;$this&#8221;) as a parameter. On a regular page the classes, variables and function can be accessed like&nbsp;this:</p>
<p><strong>page.php</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'classes/core.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$core</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> core<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a global variable.</span>
<span style="color: #b1b100;">echo</span> core<span style="color: #339933;">::</span><span style="color: #004000;">CONST_VAR</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a constant.</span>
&nbsp;
<span style="color: #000088;">$core</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hello_world</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// output: This is a global variable.</span></pre></div></div>

<p>This way there is only one variable in the global scope: $core. Another advantage is that all variables declared in core are global and accessible throughout the whole&nbsp;program.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/03/php-how-not-to-pollute-the-global-scope/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tips for writing compact PHP code</title>
		<link>http://elbertf.com/wp/2009/03/tips-for-writing-compact-php-code/</link>
		<comments>http://elbertf.com/wp/2009/03/tips-for-writing-compact-php-code/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 08:34:16 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=30</guid>
		<description><![CDATA[Writing compact code can save you  time. It&#8217;s not always recommended and often even strongly discouraged as it makes your code less readable, but for simple operations it can be more efficient. In this post I will give a few&#160;examples.

1. Drop&#160;braces
Braces aren&#8217;t required in control structures with only one expression. Sometimes it makes sense [...]]]></description>
			<content:encoded><![CDATA[<p>Writing compact code can save you  time. It&#8217;s not always recommended and often even strongly discouraged as it makes your code less readable, but for simple operations it can be more efficient. In this post I will give a few&nbsp;examples.</p>
<p><span id="more-30"></span></p>
<h4>1. Drop&nbsp;braces</h4>
<p>Braces aren&#8217;t required in control structures with only one expression. Sometimes it makes sense to drop them. It&#8217;s <em>very easy to make mistakes</em> if you ever add code to the structure, I recommend only to do this when the expression is short and fits on a single&nbsp;line.</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$module</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
    error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$module</span> <span style="color: #009900;">&#41;</span> load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span>           error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>2. Use ternary&nbsp;operators</h4>
<p>The above example can be made even more compact using <a href="http://en.wikipedia.org/wiki/%3F:">ternary&nbsp;operators</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$module</span> ? load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$module</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No module'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>3. Use &#8220;OR&#8221; instead of&nbsp;&#8220;IF&#8221;</h4>
<p>&#8220;OR&#8221; is the same as &#8220;or&#8221; and&nbsp;&#8221;||&#8221;.</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$foo</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: #000088;">$bar</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$bar</span><span style="color: #339933;">;</span></pre></div></div>

<h4>4. Don&#8217;t compare variables to&nbsp;booleans</h4>
<p>&#8220;if ( $foo == TRUE )&#8221; is the same as &#8220;if ( $foo )&#8221;. This shortcut can make your life as a programmer much&nbsp;easier:</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> has_value<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</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;">$var</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">TRUE</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</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;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> has_value<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> bool <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h4>5. Use default values for&nbsp;variables</h4>
<p>It&#8217;s usually a good idea to define important variables at the beginning of your script, instead of inside control structures (this could result in undefined variables later on). Another advantage is that you can often save an entire else-block as demonstrated in this&nbsp;example:</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'$foo is greater then 3.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'$foo is lower than or equal to 3.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'$foo is lower than or equal to 3.'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'$foo is greater then 3.'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h4>6. Assign variables inside&nbsp;conditions</h4>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$contents</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$contents</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h4>7. Group variable&nbsp;declarations</h4>
<p>Instead of prefixing every single variable declaration in a class with &#8220;public&#8221;, &#8220;protected&#8221; or &#8220;private&#8221; keywords, group&nbsp;them:</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> db
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$query</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$tables</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> db
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span>
        <span style="color: #000088;">$query</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$result</span><span style="color: #339933;">,</span>
        <span style="color: #000088;">$tables</span>
        <span style="color: #339933;">;</span></pre></div></div>

<p>Something similar can be done with regular variable declarations if they need to assign them the same&nbsp;value:</p>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span>    <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$bar</span>    <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$foobar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span>    <span style="color: #339933;">=</span>
<span style="color: #000088;">$bar</span>    <span style="color: #339933;">=</span>
<span style="color: #000088;">$foobar</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span></pre></div></div>

<h4>8. Merge arrays instead of assigning individual&nbsp;keys</h4>
<p><strong>Long:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item 1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'item 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'item 3'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'item 4'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'item 5'</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Short:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item 1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'item 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'item 3'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'item 4'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'item 5'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Even&nbsp;shorter:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item 1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'item 2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$items</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'item 3'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'item 4'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'item 5'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s it! Please share this post if you found it&nbsp;useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/03/tips-for-writing-compact-php-code/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Twitchance</title>
		<link>http://elbertf.com/wp/2009/03/twitchance/</link>
		<comments>http://elbertf.com/wp/2009/03/twitchance/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 05:55:18 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[App updates]]></category>
		<category><![CDATA[twitchance]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://ElbertF.com/?p=25</guid>
		<description><![CDATA[A few days ago I launched Twitchance, a free Twitter lottery. It&#8217;s a viral marketing experiment where I&#8217;m going to give away some cash ($500.- on the first&#160;draw).
The concept is simple; participants post a message from a sponsor on Twitter. After some time a winner is randomly selected and awarded the prize. The sponsor receives [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I launched <a href="http://twitchance.com">Twitchance</a>, a free Twitter lottery. It&#8217;s a viral marketing experiment where I&#8217;m going to give away some cash ($500.- on the first&nbsp;draw).</p>
<p>The concept is simple; participants post a message from a sponsor on Twitter. After some time a winner is randomly selected and awarded the prize. The sponsor receives amplified outreach to the online&nbsp;world.</p>
<p>Many companies offer services for free on the internet, often powered by advertisements. I figured the same could be done with a lottery. Twitter has a huge user base and <a href="http://search.twitter.com/search?q=%40twitchance">tracking specific messages</a> is easy, making it the perfect place for a project like&nbsp;this.</p>
<p>Anyone can join, all you need is a <a href="http://twitter.com">Twitter</a> and <a href="http://paypal.com">Paypal</a>&nbsp;account.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/03/twitchance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>&#8220;Just another WordPress weblog&#8221;</title>
		<link>http://elbertf.com/wp/2009/03/just-another-wordpress-webblog/</link>
		<comments>http://elbertf.com/wp/2009/03/just-another-wordpress-webblog/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 00:12:12 +0000</pubDate>
		<dc:creator>Elbert F</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://elbertf.com/?p=16</guid>
		<description><![CDATA[I started this blog to write about my on-line projects and share insights and interesting finds on the web. Occasionally I might post a few tips and tricks for programmers and&#160;designers.
I&#8217;m a programmer myself, I write most of my applications in PHP and JavaScript. I built websites for a living and often work on experimental [...]]]></description>
			<content:encoded><![CDATA[<p>I started this blog to write about my on-line projects and share insights and interesting finds on the web. Occasionally I might post a few tips and tricks for programmers and&nbsp;designers.</p>
<p>I&#8217;m a programmer myself, I write most of my applications in PHP and JavaScript. I built websites for a living and often work on experimental projects on the&nbsp;side.</p>
<p>This is my first WordPress blog, I used to share science and technology related articles on <a href="http://elbertf.blogspot.com/">Blogger</a> but never published any unique content. I also have a discontinued <a href="http://wappalyzer.tumblr.com/">blog on Tumblr</a> where I posted updates about one of my apps, <a href="http://wappalyzer.com">Wappalyzer</a>.  I&#8217;m going to post the updates here from now&nbsp;on.</p>
<h4>WordPress&nbsp;Theme</h4>
<p>I started off with the <a href="http://www.upstartblogger.com/wordpress-theme-upstart-blogger-modicus">Modicus</a> theme from <a href="http://upstartblogger.com/">Upstart Blogger</a> and turned it into something completely different. It&#8217;s a work in&nbsp;progress.</p>
<h4>Plugins in&nbsp;use</h4>
<ul>
<li><a href="http://wordpress.org/extend/plugins/disqus-comment-system/">DISQUS Comment&nbsp;System</a></li>
<li><a href="http://wordpress.org/extend/plugins/easy-twitter-links/">Easy Twitter&nbsp;Links</a></li>
<li><a href="http://www.google.com/support/feedburner/bin/answer.py?hl=en&amp;answer=78483">Feedburner&nbsp;FeedSmith</a></li>
<li><a href="http://wordpress.org/extend/plugins/google-sitemap-generator/"> Google Sitemap&nbsp;Generator</a></li>
<li><a href="http://wordpress.org/extend/plugins/wp-greet-box/"> WP Greet&nbsp;Box</a></li>
<li><a href="http://wordpress.org/extend/plugins/wp-syntax/">WP&nbsp;Syntax</a></li>
<li><a href="http://wordpress.org/extend/plugins/wp-typogrify/">WP&nbsp;Typography</a></li>
</ul>
<p>If you&#8217;re interested in what I have to say, please <a href="http://feeds2.feedburner.com/elbertf/rss">subscribe to my feed</a> and <a href="http://twitter.com/ElbertF">follow me on&nbsp;Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://elbertf.com/wp/2009/03/just-another-wordpress-webblog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
