<?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>Michiel van der Velde &#187; Michiel</title>
	<atom:link href="http://www.michielvdvelde.nl/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michielvdvelde.nl</link>
	<description>A statistical impossibility</description>
	<lastBuildDate>Tue, 27 Apr 2010 16:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Definition: Drive-by coding/scripting</title>
		<link>http://www.michielvdvelde.nl/2010/04/definition-drive-by-codingscripting/</link>
		<comments>http://www.michielvdvelde.nl/2010/04/definition-drive-by-codingscripting/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 16:01:56 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Scripting and Programming]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=195</guid>
		<description><![CDATA[Drive-by coding or scripting: Not using Object Oriented techniques while coding/scripting in order to decrease complexity and increase development speed. On the long term, this results in significant extra work. Basically, the above is my definition of &#8216;drive-by coding&#8217;. I just thought of this, and was curiously surprised when my (granted, very superficial) Google search [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>Drive-by coding or scripting:</strong> Not using Object Oriented techniques while coding/scripting in order to decrease complexity and increase development speed. On the long term, this results in significant extra work.</p></blockquote>
<p>Basically, the above is my definition of &#8216;drive-by coding&#8217;. I just thought of this, and was curiously surprised when my (granted, very superficial) Google search didn&#8217;t come up with web sites mentioning it. So I decided to update my blog (it&#8217;s about time&#8230;) with the definition.</p>
<p>I thought of it when I was scripting a simple task list for my school project in PHP. I didn&#8217;t use OOP-techniques, but just placed the PHP code between the HTML. Although it&#8217;s generally faster for smaller things, it isn&#8217;t a best prectice &#8211; obviously. But it does decrease the time needed to script something, as well as the complexity. So, in very small things, I do it. Because of the speed increase, yet not a gooed practice, I thought of &#8216;drive-by coding&#8217; to name this technique. I think it&#8217;s rather fitting.</p>
<p>Like I said, this usually only works for small things. As your program gets bigger and you work on it more often, drive-by coding will only decrease speed and increase the complexity of your program. Furthermore, most frequently used programming languages don&#8217;t even allow you to code this way (for example, Java). But PHP does.</p>
<p>This is the end of a rather small and useless post. But I&#8217;m curious to see if the name catches on. We&#8217;ll see in, four, five years? So go and use it! <img src='http://www.michielvdvelde.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/04/definition-drive-by-codingscripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cufon; fancy fonts on your web site</title>
		<link>http://www.michielvdvelde.nl/2010/03/cufon-fancy-fonts-on-your-web-site/</link>
		<comments>http://www.michielvdvelde.nl/2010/03/cufon-fancy-fonts-on-your-web-site/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 12:44:21 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=173</guid>
		<description><![CDATA[Although the title may not be entirely correct (I spent about three hours coming up with it), this blog post is about the use of fancy font types on your web site without the visitor having the font installed on their system. I first noticed this in the WordPress theme for this site, and decided [...]]]></description>
			<content:encoded><![CDATA[<p>Although the title may not be entirely correct (I spent about three hours coming up with it), this blog post is about the use of fancy font types on your web site without the visitor having the font installed on their system. I first noticed this in the WordPress theme for this site, and decided to see how it was done.<br />
In essence, the headings on the site, are a special font. This all is implemented in JavaScript, with support for most large browsers (I tested it in Internet Explorer, Firefox, Chrome and Safari with success).</p>
<h2>So, what is Cufon?</h2>
<p>As you see the heading right above here, this is an example of what Cufon does. Basically it has taken the text between the &lt;h2&gt;heading&lt;/h2&gt; and &#8216;replaced&#8217; it with JavaScript-generated images of the text in the desired font. This is very handy if you want to use a non-standard font for your headings, for example. And the best thing: if the browser doesn&#8217;t support it, or has JavaScript disabled, the visitor will just see the header in the regular font!</p>
<h2>How does it work?</h2>
<p>Cufon actually has two parts:</p>
<ol>
<li>The font generator, which converts fonts through SVG and VML to JSON;</li>
<li>The rendering engine; the JavaScript code that shows the font.</li>
</ol>
<h3>The generator</h3>
<p><a title="Cufon font generator" href="http://cufon.shoqolate.com/generate/" target="_blank">You can find the generator here</a>, where you can select TrueType &#8211; TTF, OpenType &#8211; OTF, Printer Font Binary &#8211; PFB en PostScript fonts from your own computer to convert. After you&#8217;ve set the appropriate options, it gives you a .js file containing the font information, which you can then use.</p>
<h3>The renderer</h3>
<p>The renderer is nothing more than a simple (well, simple&#8230; you know what I mean) JavaScript file. <a title="The Cufon JavaScript renderer file" href="http://cufon.shoqolate.com/js/cufon-yui.js" target="_blank">You can find it here</a>.<br />
If you have the font and the renderer files, you can put everything together.</p>
<h3>Putting it together</h3>
<p>If you have the .js file of your favorite font, and the renderer .js file, then you&#8217;re ready to put it all together! This small example shows how this is done:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
   &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
        &lt;script src=&quot;cufon-yui.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;Vegur_300.font.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;
            Cufon.replace('h1');
        &lt;/script&gt;
    &lt;/meta&gt;&lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;This text will be shown in Vegur.&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>And that is all! Good luck experimenting!</p>
<h2>References</h2>
<ol>
<li><a title="Cufon home page" href="http://cufon.shoqolate.com" target="_blank">Cufon home page</a></li>
<li><a title="Cufon font generator" href="http://cufon.shoqolate.com/generate/" target="_blank">Cufon font generator</a></li>
<li><a title="The Cufon JavaScript renderer file" href="http://cufon.shoqolate.com/js/cufon-yui.js" target="_blank">Cufon renderer JavaScript file</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/03/cufon-fancy-fonts-on-your-web-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agile software development: Scrum</title>
		<link>http://www.michielvdvelde.nl/2010/03/agile-software-development-scrum/</link>
		<comments>http://www.michielvdvelde.nl/2010/03/agile-software-development-scrum/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 08:36:18 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Agile software development]]></category>
		<category><![CDATA[Scripting and Programming]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=164</guid>
		<description><![CDATA[Software development can be done in lots and lots of different ways. A software company, whether it develops in-house software or software on order (or both), probably has adopted one of the more well known ideologies for this. For a long time, sequential software development was prevalent. One of these methods is known as the [...]]]></description>
			<content:encoded><![CDATA[<p>Software development can be done in lots and lots of different ways. A software company, whether it develops in-house software or software on order (or both), probably has adopted one of the more well known ideologies for this.</p>
<div class="wp-caption alignleft" style="width: 352px"><img title="The Waterfall" src="http://www.software-development-resource.com/images/waterfall_software_process.jpg" alt="" width="342" height="259" /><p class="wp-caption-text">The Waterfall model, a non-agile development methodology</p></div>
<p>For a long time, <strong>sequential</strong> software development was prevalent. One of these methods is known as the <a title="The Waterfall model on Wikipedia" href="http://en.wikipedia.org/wiki/Waterfall_model" target="_blank">Waterfall model</a> (see the image on the left). The Waterfall model originated in the manufacturing and construction industries, where after-the-fact changes were costly to say the least.</p>
<p>A Waterfall has several blocks, as you can see in the picture. Every &#8216;block&#8217; has its own specialists who work on it. When one is completed, the work is handed down to the next block, making going back impossible (down, not up). So requirements were not allowed to be altered after the design started, and the design could not be altered when the implementation started.</p>
<p>As you can imagine, this form a very rigid and un-agile software development model. This may have worked fifteen years ago, but the world has sped up since then, and software development needs to change along with it.</p>
<h2>Scrum, or SCRUM</h2>
<p>Scrum (sometimes written capitalized SCRUM) is an agile software development methodology that has been used in large corporations such as Microsoft, IBM, Google and Crowd Control Productions (CCP) in their development of the MMO <a title="Eve Online web site" href="http://www.eveonline.com" target="_blank">Eve Online</a> (<a title="Presentation about Scrum and Eve Online by CCP Inc." href="http://www.youtube.com/watch?v=GqsReCZD4hc" target="_blank">click here to see a presentation of CCP about Scrum and Eve on EVE Fanfest 2009</a>).<br />
Although considered &#8216;new&#8217; by some people, Scrum was actually introduced by Hirotaka Takeuchi and Ikujiro Nonaka in 1986. In 1991, DeGrace and Stahl named this approach Scrum, after a rugby term where the whole team “tries to go to the distance as a unit, passing the ball back and  forth”.</p>
<div class="wp-caption aligncenter" style="width: 560px"><img title="An example of the Scrum process" src="http://www.methodsandtools.com/archive/scrum1.gif" alt="" width="550" height="369" /><p class="wp-caption-text">A graphical representation of the Scrum process</p></div>
<p style="text-align: center;">
<p>So, what is so agile about it and why is it more usable than the Waterfall model?<br />
People are divided into teams (one or more) of 5 to 9 people, which will be working together for at least one &#8220;sprint&#8221;; a period of one to four weeks where a predetermined amount of features are developed. These features are taken from the &#8216;product backlog&#8217;; a list of prioritized items that need to be implemented in the software. This backlog is created by the Product Owner, which may be the customer, and prioritized by the Product Owner as well.<br />
It is important to note that the team is represented by people from all relevant specialties. This may include programmers, testers, database specialists, and others.<br />
At the beginning of a sprint cycle, the team will select the items from the product backlog it thinks can complete in the time set for the sprint (typically one to four weeks in length). These items become the &#8216;sprint backlog&#8217;, and contain a list of things that need to be done in a high level way. For example, so-called &#8216;user stories&#8217; can be used for this. Simply put, this is a small description of the feature: &#8220;As a user, I would like to be able to send private messages to other users&#8221;, or &#8220;As an administrator, I would like to be able to ban spammers&#8221;. These user stories can not be changed during the sprint, but they can be changed before or after. The user stories are expanded into tasks, which typically take 1 to maximal 16 hours to implement.</p>
<p>Every day, there is a &#8216;daily scrum&#8217;, which is a short meeting (typically limited to 15 minutes) where every team member answers three questions:</p>
<ol>
<li>Wat have you done yesterday?</li>
<li>What are you going to do today?</li>
<li>Are you running into any problems?</li>
</ol>
<p>The Scrum Master is the &#8216;manager&#8217; of the team, and is responsible for making sure the team performs optimally. This includes solving any problems team members might encounter, which can be anything from a broken calculator to customer service for a supplier not returning their calls.</p>
<p>When the sprint is over, there is a &#8216;potentially shippable product&#8217; (e.g. the software builds and runs), and a demo is held to showcase the work done during the sprint. Then, new items can be picked from the product backlog and the next sprint can commence.</p>
<h2>Tip of the iceberg</h2>
<p>I think Scrum is a promising way to develop software, especially to add features or update existing software. It&#8217;s too bad you need a whole team to implement it, though, but perhaps I will use a slightly modified version on my one person projects. It is only a framework, after all.</p>
<p>The information in this blog post is only the tip of the proverbial iceberg. There is so much more the Scrum, that it would take me ages to type a blog post on it. If you&#8217;re interested in reading more about Scrum, I suggest you take a look at the following web sites.</p>
<ul>
<li><a title="Mountain Goat Software" href="http://www.mountaingoatsoftware.com" target="_blank">Mountain Goat Software</a></li>
<li><a title="Scrum on Wikipedia" href="http://en.wikipedia.org/wiki/Scrum_%28development%29" target="_blank">The Wikipedia page about Scrum</a></li>
<li><a title="The Scrum Alliance" href="http://www.scrumalliance.org/" target="_blank">The Scrum Alliance</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/03/agile-software-development-scrum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Namespaces in php 5.3</title>
		<link>http://www.michielvdvelde.nl/2010/01/namespaces-in-php-5-3/</link>
		<comments>http://www.michielvdvelde.nl/2010/01/namespaces-in-php-5-3/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 12:47:53 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=149</guid>
		<description><![CDATA[PHP 5.3, introduced in June 2009 and has some really interesting enhancements. Some of you may know about the promise of namespace support in php 6. Because this was a popular requested feature, namespaces have been introduced in php 5.3. What are namespaces and why are they convenient? &#8216;Namespaces&#8217; are default in almost every other [...]]]></description>
			<content:encoded><![CDATA[<p>PHP 5.3, introduced in June 2009 and has some really interesting enhancements. Some of you may know about the promise of namespace support in php 6. Because this was a popular requested feature, namespaces have been introduced in php 5.3.</p>
<h2>What are namespaces and why are they convenient?</h2>
<p>&#8216;Namespaces&#8217; are default in almost every other (OOP) language, such as C++ and C#. They separate classes and other objects (such as methods) in logical units, mostly to avoid name collisions. A program (or web site, as is probably the case in php) may use several frameworks and libraries. These may hold methods and/or classes that are named the same, for example a class named <em>Date</em>. Prior to php 5.3, this would lead to the well known error &#8220;<em>Could not redeclare class <strong>Date</strong> in file/name.php on line no</em>&#8220;. This, of course, could be a problem when you want to use multiple frameworks and/or third-party libraries.</p>
<p>The problem of name colissions was dealt with before by using something called &#8216;poor man&#8217;s namespacing&#8217;, which has been used in, for example, the Zend Framework. This looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">class</span> Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive <span style="color: #000000; font-weight: bold;">extends</span> Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFilter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Search_Lucene_Analysis_TokenFilter_LowerCase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This of course is not very handy all the time. So, how do namespaces solve this problem?</p>
<h2>Namespaces in php 5.3</h2>
<p>A namespace in php can be thought of as an extra layer around (part of) your code. Every class en method name within it is unique and does not conflict with classes or methods with the same name in other namespaces.</p>
<p>To declare a namespace in php, use the keyword &#8216;namespace&#8217; on the first line of your file. Your classes and methods you define below it. All code within that file will be in that namespace. Let&#8217;s look at an example on how to use namespaces:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">namespace</span> MichielvdVelde\Core<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Database
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The class <em>Database</em> will now reside in the namespace <em>MichielvdVelde\Core</em>. If you were to make another namespace, which also holds a class named Database, this would be fine.</p>
<p>So, how do you use classes within a namespace? This is really kind of simple. There are two method.</p>
<h3>Method one</h3>
<p>Add the namespace to the declaration of the class. Like this:</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'MichielvdVelde/Core.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MichielvdVelde\Core\Database<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this method is not really an improvement over poor man's namespacing. Therefore, there is a second method.</p>
<h3>Method two</h3>
<p>By using the 'use' keyward, you cam import namespaces in your code. This more closely resembles namespacing as implemented in other languages such as C++ and C#.</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'MichielvdVelde/Core.php'</span><span style="color: #339933;">;</span>
&nbsp;
use MichielvdVelde\Core <span style="color: #b1b100;">as</span> CORE<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$db</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CORE\Database<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you can see, this is more aliasing than really importing. But still, this method is very useful.</p>
<h2>Gotcha's</h2>
<h3>Functions are also part of namespaces</h3>
<p>When defining functions in files with the 'namespace' keyword at the top, thsey are also part of that namespace.</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">namespace</span> MichielvdVelde\Core<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getDatabase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'MichielvdVelde/Core.php'</span><span style="color: #339933;">;</span>
&nbsp;
getDatabase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Geeft E_FATAL error: Undefined function getDatabase()</span>
&nbsp;
use MichielvdVelde\Core <span style="color: #b1b100;">as</span> CORE<span style="color: #339933;">;</span>
&nbsp;
CORE\getDatabase<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This does work</span></pre></div></div>

<h3>Autoload changes</h3>
<p>Autoload on Windows does not use the \ very well. You may need to change your autoload function for this:</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">function</span> __autoload<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\\'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require</span> <span style="color: #000088;">$className</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MichielveVelde\Core\Database<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also note that you need to define __autoload within the global scope. If you define it within a namespace, php won't find it. If you do want to use the autolaod function from within a namespace, use the <em>spl_autoload_register</em> function:</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">spl_autoload_register</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MichielvdVelde\\Core\\Autoloader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Conclusion</h2>
<p>PHP 5.3 introduces support for namespaces which will be very handy in organizing and cleaning up your code. Although it may take some time for web hosters to support php 5.3, you can experiment with it by installing the latest version of <a title="XAMPP" href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMPP</a> on your omputer, which has php 5.3 included.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/01/namespaces-in-php-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Opinion] Apple&#8217;s Quest for World Dominance &#8211; the iPad</title>
		<link>http://www.michielvdvelde.nl/2010/01/opinion-apples-quest-for-world-dominance-the-ipad/</link>
		<comments>http://www.michielvdvelde.nl/2010/01/opinion-apples-quest-for-world-dominance-the-ipad/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 13:01:53 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[ipod]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[tablet pc]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=132</guid>
		<description><![CDATA[Disclaimer: obsessed Apple fans should stop reading right now, unless you can take criticism. The Mac, the Macbook, the iPod, the iPhone, and now the iPad &#8211; God save us; Apple is taking over the world! First of all, Apple claims it&#8217;s intention is not to compete with the personal computer and Microsoft&#8217;s operating system [...]]]></description>
			<content:encoded><![CDATA[<p><em>Disclaimer: obsessed Apple fans should stop reading right now, unless you can take criticism.</em></p>
<p>The Mac, the Macbook, the iPod, the iPhone, and now the iPad &#8211; God save us; Apple is taking over the world!<br />
First of all, Apple claims it&#8217;s intention is not to compete with the personal computer and Microsoft&#8217;s operating system Windows. But we all know this is bullshit. Apple is on a Quest for World Wide Dominance and you know it! Just like the New World Order conspiracy theories, Apple is silently building a strong user base by snooping off market shares from a lot of markets!</p>
<h2>Take over the world, while you still can</h2>
<p>It began with the computer; the Apple Mac. But that wasn&#8217;t enough. It wasn&#8217;t enough that software developers are practically forced to write software for both Windows and Mac, no sir. Everyone calls Microsoft restrictive in their policies regarding Windows, but that is nothing compared to Apple&#8217;s stance. You couldn&#8217;t even run Mac on an ordinary pc &#8211; apparently the standardized Von Neumann architecture as implemented since the advent of the microcomputer in 1981 from IBM isn&#8217;t good enough for them (why a PowerPC CPU instead of an Intel/AMD CPU that is compatible with the rest of the world?).</p>
<p>Since then, Apple has showed laptops (such as the Macbook Air, an &#8216;ultra-thin&#8217; laptop without even a dvd drive), MP3 and Media players (the whole iPod range, from the original iPod to ther iPod video and what not), mobile phones (the iPhone, which is more restrictive than a 18th century corset), and now the iPad &#8211; a real Apple table computer!<br />
First of all; who would ever want to have a tablet computer? Okay, web designers maybe. But Regular Rick isn&#8217;t interested in them &#8211; at least when they&#8217;re not working in Atlantis, the city of the Ancients (Stargate Atlantis reference, if you saw it, you know what I mean).<br />
Second, it is the TWENTY-FIRST CENTURY for crying out loud! What in God&#8217;s name was Apple thinking when they DIDN&#8217;T IMPLEMENT MULTITASKING?! As with the iPhone, where multitasking is also noticeably absent, the iPad also does not have multitasking. I can not wrap my mind around this; in a world of two, four, six or even eight core processors, the Apple hardware doesn&#8217;t even support basic multitasking &#8211; something that was possible from very early in Windows. This, in my eyes, is an idiotic decision, both from a hardware and a marketing standpoint.</p>
<h2>Marketing: follow the hype</h2>
<p><a href="http://www.michielvdvelde.nl/wp-content/uploads/2010/01/190745_CAPS101_571_269536e.jpg"><img class="size-full wp-image-145 alignleft" title="Steve Jovs with the iPad" src="http://www.michielvdvelde.nl/wp-content/uploads/2010/01/190745_CAPS101_571_269536e.jpg" alt="" width="299" height="235" /></a>The iPad has Apple&#8217;s own 1GHz CPU implemented. This ARM-based processor operates at 1 Gigahertz, which is &#8216;quite high&#8217; (the only other 1GHz ARM-processor is implemented in Google&#8217;s Nexus One smart phone). This tells me the iPad is not meant as a full blown computer, because even simple laptops have dual core processors these days. I guess Apple wanted to keep the costs down on the hardware (so they could charge more for the design).</p>
<p>The iPad is in my opinion a ridiculous addition to the Apple fleet of hardware. Things that consumers take for granted these days are not implemented, there are extreme limitations to what you can run on it (as with the iPhone, you can only download and install apps from the Apple Store, meaning Apple decides what will and what will not run on somebody&#8217;s iPad. Although jail-breaking is probably in the iPad&#8217;s future.</p>
<p>Basic flaws of the iPad:</p>
<ul style="list-style-image: url(http://www.michielvdvelde.nl/no.png);">
<li>No multitasking</li>
<li>No camera</li>
<li>No Flash</li>
<li>Not even a single USB port, no HDMI or other display ports</li>
<li>Once again Apple controls the customer by determining which apps the customer can or can not run, through their App Store</li>
</ul>
<h2>So&#8230;?</h2>
<p>So the iPad will be the next big thing.</p>
<p><strong>Addition<br />
</strong>Don&#8217;t get me wrong; I think Apple is great. The only thing I really dislike is the amount of control Apple holds over its customers, with only allowing certified applications to run &#8211; and even then, only one at a time (this is true for the mobile platforms of the iPhone and iPad). Another big objection of mine is they charge ridiculous prices for what I consider to be sub standard hardware (in terms of speed etc), just because &#8216;it looks nice&#8217;. But i have to applaud Apple too; the customers buy it completely. Hail Apple&#8217;s marketing strategy &#8211; the design is a one-time expense, hardware costs need to be spent with every unit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/01/opinion-apples-quest-for-world-dominance-the-ipad/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What does the next decade have in store for us?</title>
		<link>http://www.michielvdvelde.nl/2010/01/what-does-the-next-decade-have-in-store-for-us/</link>
		<comments>http://www.michielvdvelde.nl/2010/01/what-does-the-next-decade-have-in-store-for-us/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 13:59:54 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Future]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=124</guid>
		<description><![CDATA[This is the question that so-called &#8216;futurists&#8217; are trying to answer. Because the first year of the second decade of the second millennium has just begun, and because we are advancing toward a technological singularity, these are extremely turbulent times of rapid (technological) advances. Is this really happening? Yes! Technological advances happen much more quickly [...]]]></description>
			<content:encoded><![CDATA[<p>This is the question that so-called &#8216;futurists&#8217; are trying to answer. Because the first year of the second decade of the second millennium has just begun, and because we are advancing toward a <a title="Technological singularity on Wikipedia" href="http://en.wikipedia.org/wiki/Technological_singularity" target="_blank">technological singularity</a>, these are extremely turbulent times of rapid (technological) advances. Is this really happening? Yes! Technological advances happen much more quickly every time, and this will continue to happen. Futurist Ray Kurzweil explains this with an example:</p>
<blockquote><p>When I was an MIT undergraduate in 1965, we all shared a computer that took up half a building and cost tens of millions of dollars. The computer in my pocket today is a million times cheaper and a thousand times more powerful. That’s a billion-fold increase in the amount of computation per dollar since I was a student.</p></blockquote>
<p>Also, keep in mind <a title="Moore's law on Wikipedia" href="http://en.wikipedia.org/wiki/Moore%27s_law" target="_blank">Moore&#8217;s Law</a>, which claims that the amount of transistors on CPU&#8217;s doubles every 18 to 24 months. Until now, this law has been true, and according to experts, will remain true for some time.<br />
So, let&#8217;s look at some predictions made by several futurists, shall we? Let&#8217;s take a look at the next decade.</p>
<h2>The decade according to Jack Uldrich</h2>
<p><img class="alignright" title="Jack Uldrich" src="http://speakerarticles.net/wp-content/uploads/2009/12/Uldrich-Jack-bio.jpg" alt="Jack Uldrich" width="150" height="215" />These are some of the predictions done by Jack Uldridge, who manages the web site <a title="Jack Uldrich's Jump the Curve" href="http://www.jumpthecurve.net" target="_blank">Jump the Curve</a>. He is a known futurist, author and speaker, hired by lots and lots of companies to speak at conferences and such. For more info about him, was well as hit &#8211; very interesting &#8211; blog posts, go to his web site.</p>
<p>Among others, Jack predicts the cost of sequencing an individual&#8217;s genome will drop to $1,000 or lower. This allows Average Joe to have his genome sequenced and will lead to personalized medical treatment and medicine based on the patient&#8217;s genes.<br />
Furthermore, he predicts doctors will be able to operate people over the internet using robots. This will allow a specialist to operate a patient in another country without having to gly that specialist over, which is expensive. Also, brain-neural interfaces will be introduced leading to a myriad of possibilities.</p>
<h2>To 2020; what lies on the horizon, if it were up to Ray Kurzweil</h2>
<p><img class="alignleft" title="Ray Kurzweil" src="http://www.slconvention.org/wp-content/uploads/2009/06/ray-kurzweil-headshot.jpg" alt="Ray Kurzweil" width="165" height="201" /><a title="The web site of Ray Kurzweil" href="http://www.kurzweilai.net/" target="_blank">Ray Kurzweil</a>, a &#8216;top futurist&#8217;, has done some predictions about the next decade as well. Let&#8217;s take a look at what the next decade has in store for us according to this man, shall we?</p>
<p>Memory devices will be in our clothing, and the meaning of &#8216;smartphone&#8217; will transform. Instead of looking at a tiny screen, images will be projected directly on our retinas, providing an image as large as our field of view. We can expect information about things around us to be displayed on this, essentially implementing augmented reality. The Internet will make sure we can see the latest information on our screens, as well as new forms of advertising, such as floating ads in mid-air, streamed through the Internet by companies such as Google (the part about floating ads I added, but it isn&#8217;t a far stretch). We&#8217;ll watch movies and read books in this new virtual playground.<br />
Renewable energy will take a dive and solar power costs will decrease, making it a viable &#8211; and affordable &#8211; means of producing clean energy. Other than that, our &#8216;software&#8217;, our base DNA, will be able to be &#8216;updated&#8217;; to live longer, and to reduce or remove decease and cancer.</p>
<h2>Stay sober</h2>
<p>Now, such wild predictions have been done for decades. Remember the &#8216;a fully functional humanoid robot in every household by the year 2000&#8242;? That hasn&#8217;t happened, an I suspect many of the things mentioned above will not, or to a lesser degree, happen as well. But is is important to keep in mind the technological singularity; technological advances happen quicker and quicker, and maybe in 2020 I look back at this post (assuming it still exists somewhere) and look at the ignorance of these futurists; who knows.<br />
The next decade will without a doubt be an interesting one, with lots and lots of futuristic discoveries and new technologies emerging. To close, here are five of my predictions for the next decade:</p>
<ol>
<li>Google will grow even larger;</li>
<li>We will still use fossil fuels for at least 50% of energy production, and most cars will still run on them;</li>
<li>Exciting new technologies to increase the welfare of entire counties, and even the world &#8211; for example, fields of solar panels to produce clean energy &#8211; will still not happen because of the bureaucracy and &#8216;budgetary constraints&#8217;;</li>
<li>Kids will still run around with guns and education will not be available for everyone;</li>
<li>And maybe one positive point; experimental UCAV&#8217;s (Unmanned Combat Areal Vehicles) will reduce the casualties of war (mostly for the United States though).</li>
</ol>
<p>Maybe it&#8217;s a bleak view, but I&#8217;d love to be proven wrong.</p>
<p><strong>What are your predictions for the decade? Comment and share your vision!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2010/01/what-does-the-next-decade-have-in-store-for-us/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The next phase of virtual reality</title>
		<link>http://www.michielvdvelde.nl/2009/12/the-next-phase-of-virtual-reality/</link>
		<comments>http://www.michielvdvelde.nl/2009/12/the-next-phase-of-virtual-reality/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 11:00:09 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Future]]></category>
		<category><![CDATA[consensus]]></category>
		<category><![CDATA[netforce]]></category>
		<category><![CDATA[reality]]></category>
		<category><![CDATA[virtual]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=95</guid>
		<description><![CDATA[Today, three dimensional games and simulations on two dimensional surfaces (computer monitors) are real popular and the quality of the graphics is increasing every minute, it seems. Still, no matter how great the graphics, it is still on a 2D surface and will never be really real to the person using it. So, how cán [...]]]></description>
			<content:encoded><![CDATA[<p>Today, three dimensional games and simulations on two dimensional surfaces (computer monitors) are real popular and the quality of the graphics is increasing every minute, it seems. Still, no matter how great the graphics, it is still on a 2D surface and will never be really real to the person using it.</p>
<p>So, how cán this be done? Obviously you all know those bulky Head-Up-Displays (HUD&#8217;s) with built-in monitors so you are in a semi-real world. Some even provide head tracking so you can look around. But this still isn&#8217;t really real. So, how do we create a virtual world that approaches our <a title="Consensus Reality" href="http://en.wikipedia.org/wiki/Consensus_reality" target="_blank">consensus reality</a>? A very interesting book series, called <strong>Netforce Explorers</strong>, sketches a novel approach to this; someone with an implant can &#8216;plug in&#8217; to the Net, which is nothing more than a realistically looking world within the computer.<br />
Although the idea of a &#8216;brain implant&#8217; may scare some people away from it, this actually is really intriguing idea; the central nervous system is connected directly to the computer to provide direct neural input, bypassing the &#8216;real&#8217; senses of the body.</p>
<p>The reason I started this post is to show you the following video. The man you see on it is Ray Kurzweil, &#8220;Inventor, Author, Futurist&#8221;. Enjoy his views on virtual reality in the future.</p>
<p><script src="http://video.bigthink.com/player.js?height=341&amp;width=512&amp;autoplay=0&amp;embedCode=lkNzNpOlH_nJ7UFTXrYnZdtlgk6bkKn8"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2009/12/the-next-phase-of-virtual-reality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Forensic IT How-To: Using Volatility to examine your RAM dump</title>
		<link>http://www.michielvdvelde.nl/2009/12/forensic-it-how-to-using-volatility-to-examine-your-ram-dump/</link>
		<comments>http://www.michielvdvelde.nl/2009/12/forensic-it-how-to-using-volatility-to-examine-your-ram-dump/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 01:00:17 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Forensic How-To's]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=84</guid>
		<description><![CDATA[In the previous forensic how-to, we have made a dump of your computer&#8217;s active RAM, or Random Access Memory. This is the memory that stores everything you&#8217;re working on and with when your computer is on. Viruses and other malware can run exclusively in your RAM, but you can also possibly find cryptographic keys &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous forensic how-to, we have made a dump of your computer&#8217;s active RAM, or Random Access Memory. This is the memory that stores everything you&#8217;re working on and with when your computer is on. Viruses and other malware can run exclusively in your RAM, but you can also possibly find cryptographic keys &#8211; for example, for whole disk encryption &#8211; here.<br />
As you can imagine, whether you&#8217;re a forensic IT&#8221;ist (working for the police or a private company) or a home user, you can get some very interesting information from your RAM dump. So, let&#8217;s Start!</p>
<p><strong>Required software<br />
</strong>Before we can actually start, we need some software. We need two pieces of software. Well, we actually need one, but to use it, we need another.<br />
You may or may not be familiar with Python. Python is a multi-purpose scripting language where even you can script in. From entire programs to dedicated scripts for data processing, it&#8217;s possible.<br />
&#8220;So, where can I find this Python?&#8221; you ask? Well, we&#8217;ll go to <a title="Python home page" href="http://www.python.org/" target="_blank">python.org</a>. Please make sure you <strong>download the 2.x.x version of Python</strong> (I am using version 2.6.4)! The newer version, in the 3.x.x range, will not work with the next piece of software we&#8217;ll need.<br />
Install Python and go to the directory where you installed it.</p>
<p>The second piece of software we need it actually written in Python. It is called the Volatility Memory Forensics Framework. This software is capable of analyzing the RAM dump we made earlier. You can find the software on <a title="Volatility Memory Forensics Framework" href="https://www.volatilesystems.com/default/volatility/" target="_blank">volatilesystems.com</a>. Download the newest version (I am using version 1.3 beta in this post). Download, unpack and remember where you&#8217;ve unpacked it.</p>
<p>So, to sum up, we need the following two pieces of software, in order:</p>
<ol>
<li><a title="Python home page" href="http://www.python.org/" target="_blank">Python for Windows</a></li>
<li><a title="Volatility Memory Forensics Framework" href="https://www.volatilesystems.com/default/volatility/" target="_blank">Volatility Memory Forensics Framework</a></li>
</ol>
<p>Download and install these two components according to the instructions above.</p>
<p><strong>Step One: the command prompt and setting it up<br />
</strong>Yes, a young person&#8217;s nightmare; the command prompt. For the older &#8211; or crazier &#8211; people among you, you are most likely quite familiar with the command prompt.</p>
<p>To open one, simply <em>press the Start button</em>, and whether or not you&#8217;re on an OS higher than XP, click &#8220;Execute&#8230;&#8221;. If you have a search field, don&#8217;t. Then type the command <em>cmd</em>. This will open a command prompt for you.<br />
Now we only need to set it up. We need to add a path to the cmd&#8217;s path string. For this, you need the directory you installed Python in. For me, this is D:\Program Files\Python 2.6.4. Type in the following (change the path to Python with your own path):</p>
<div class="cmd">&gt; PATH=%PATH%;D:\Program Files\Python 2.6.4</div>
<p>This will add your Python&#8217;s install path to the paths of the command prompt. For experienced cmd/DOS people, you can of course do this in your sleep.</p>
<p>Now, go to the folder you unpacked Volatility in. For me, this is C:\Users\Michiel\Desktop\Volatility-1.3_Beta. I do this with the following command:</p>
<div class="cmd">&gt; cd C:\Users\Michiel\Desktop\Volatility-1.3_Beta</div>
<p>Now, you are in the folder you unpacked Volatility to. We are now ready to start for real.</p>
<p><strong>Step Two: Dissect that dump!<br />
</strong>Now you are ready to start for real. Yes &#8211; this time I mean it. If you&#8217;ve been smart enough to read the Readme.txt file that came along with Volatility, you know what is possible.</p>
<p>For now, we&#8217;ll just print out a list of processes that were running when the RAM dump was made. My dump is located at D:\ram.dmp. I type in the following:</p>
<div class="cmd">&gt; pyhton volatility pslist -f D:\ram.dmp</div>
<p>This gives me a list of all running processes, as demonstrated in this image (note that it may take a while &#8211; depending on the size of your RAM dump &#8211; before any results show up):</p>
<p><a href="http://www.michielvdvelde.nl/wp-content/uploads/2009/12/vol_1.png"><img class="aligncenter size-medium wp-image-86" title="vol_1" src="http://www.michielvdvelde.nl/wp-content/uploads/2009/12/vol_1-300x154.png" alt="" width="300" height="154" /></a></p>
<p>These processes were running when I made the dump. You can for example compare the list with the list your task manager process list, to find &#8216;hidden&#8217; processes that might indicate malicious behavior.</p>
<p>Of course the Volatility Memory Forensics Framework can do lots and lots more. You can find a list of all its options in the readme file that accompanied it. For this example&#8217;s sake, we&#8217;ll show off one more:</p>
<div class="cmd">&gt; pyhton volatility connscan-f D:\ram.dmp</div>
<p>This produces a list of all network connections that were active when the dump was made (this, also, may take a while):</p>
<p><a href="http://www.michielvdvelde.nl/wp-content/uploads/2009/12/vol_2.png"><img class="aligncenter size-medium wp-image-88" title="vol_2" src="http://www.michielvdvelde.nl/wp-content/uploads/2009/12/vol_2-300x153.png" alt="" width="300" height="153" /></a></p>
<p><strong>Final words<br />
</strong>And then some final words. The Volatility Framework is of course (almost) infinity more feature rich than shown in this how-to. I encourage you to walk through the readme file, it will provide you with a list of features.<br />
I wish you much excitement when scavenging through your own memory dumps with Volatility. In the next how-to &#8211; I have no idea when it will come, though &#8211; I will write a piece about scanning for viruses within your dump.</p>
<p>Hope to see you later and don&#8217;t forget to leave a comment if you liked it! See ya!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2009/12/forensic-it-how-to-using-volatility-to-examine-your-ram-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security article: Password security in PHP</title>
		<link>http://www.michielvdvelde.nl/2009/12/security-article-password-security-in-php/</link>
		<comments>http://www.michielvdvelde.nl/2009/12/security-article-password-security-in-php/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 13:59:08 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=71</guid>
		<description><![CDATA[This article will deal with password security. Especially, passwords of your web site&#8217;s (or program&#8217;s) users. Although the title of this posts suggests it only applies to PHP scripts, it can in fact be used for and programming or scripting language (except the PHP examples, or course). On many web sites, visitors can register themselves, [...]]]></description>
			<content:encoded><![CDATA[<p>This article will deal with password security. Especially, passwords of your web site&#8217;s (or program&#8217;s) users. Although the title of this posts suggests it only applies to PHP scripts, it can in fact be used for and programming or scripting language (except the PHP examples, or course).</p>
<p>On many web sites, visitors can register themselves, for example to be able to post on the forums or place comments. These users have to fill in a password, that allows only them to log in with that specific name on that specific user account.<br />
But, how is this password stored? There are basically three methods, ranging from dumbest to smartest:</p>
<ol>
<li>Clear text, the password directly into the database or other storage medium;</li>
<li>Encrypted, the password encrypted with an algorithm (e.g. AES), with a key;</li>
<li>Hashed; a one-way hash (e.g. MD5, SHA1).</li>
</ol>
<p>As you might suspect, <strong>storing the password as clear text is the most idiotic thing you can do</strong>! Imagine a hacker breaks into your database; he instantly has all passwords for all users on your web site. Is that what you want? I think not.</p>
<p>Option two is storing the password as encrypted text. This requires an encryption algorithm, such as <a title="Advanced Encryption Standard" href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" target="_blank">Advanced Encryption Standard</a>, and a key. This requires the key to be stored as well, and no matter how good you put it away. On the other hand, it allows you to decrypt the password and use it for verification. And you can give them their original password when they&#8217;ve lost it. But this still isn&#8217;t the best solution. See option three.</p>
<p><strong>Option three: hashes<br />
</strong>The third option is in my opinion, and that of a lot of people who know, hashing. A hash is, according to Wikipedia:</p>
<blockquote><p>A <strong>cryptographic hash function</strong> is a <a title="Algorithm" href="http://en.wikipedia.org/wiki/Algorithm">deterministic procedure</a> that takes an arbitrary block of <a title="Data" href="http://en.wikipedia.org/wiki/Data">data</a> and returns a fixed-size <a title="Bit" href="http://en.wikipedia.org/wiki/Bit">bit</a> string, the (<strong>cryptographic</strong>) <strong>hash value</strong>, such that an accidental or intentional change to the data will change the hash value. The data to be encoded is often called the &#8220;message&#8221;, and the hash value is sometimes called the <strong>message digest</strong> or simply <strong>digest</strong>.</p></blockquote>
<p>So, a hash is a string that is based 0n the original text. This is handy, as it is almost impossible to reverse the hash, so the password is safe. And when you need to check a password, you simply hash the inputted password too and compare.</p>
<p>What kind of hash functions are there? Basicly, the following two are the most used:</p>
<ol>
<li>MD5</li>
<li>SHA(1)</li>
</ol>
<p><strong>MD5<br />
</strong>MD5 stands for <strong>Message Digest 5</strong>, and has been developed by Ron Rivest in 1991 to replace MD4. How can you use it in php?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Method one</span>
<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: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Method two</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;">'MD5'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This results in a 32-digits hexadecimal string, for example <strong>5f4dcc3b5aa765d61d8327deb882cf99</strong>. This is always the same for the same string. This provides a great method for password saving, because the password can never (or, with extreme difficulty) be reverse-engineered. When you need to check a password, you simply hash that too, and compare the strings.</p>
<p><strong>SHA1<br />
</strong>SHA1 is another cryptographic hash function. According to Wikipedia:</p>
<blockquote><p>The <strong>SHA hash functions</strong> are a set of <a title="Cryptographic hash function" href="http://en.wikipedia.org/wiki/Cryptographic_hash_function">cryptographic hash functions</a> designed by the <a title="National Security Agency" href="http://en.wikipedia.org/wiki/National_Security_Agency">National Security Agency</a> (NSA) and published by the <a title="National Institute of Standards and Technology" href="http://en.wikipedia.org/wiki/National_Institute_of_Standards_and_Technology">NIST</a> as a U.S. <a title="Federal Information Processing Standard" href="http://en.wikipedia.org/wiki/Federal_Information_Processing_Standard">Federal Information Processing Standard</a>. SHA stands for <strong>Secure Hash Algorithm</strong>.</p></blockquote>
<p>SHA1 generates a hexadecimal string of 40 characters, instead of the 32 of MD5. SHA1 is considered more secure. Using this in php is not more difficult:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Method one</span>
<span style="color: #000088;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sha1</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Method two</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;">'SHA1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This generates the has, for example<strong> 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8</strong>.</p>
<p>This is it for now. I&#8217;ll write an article about cracking hash ciphers in the furure, which is mainly <strong>brute-forcing</strong>. Bye-bye.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 339px; width: 1px; height: 1px;">A <strong>cryptographic hash function</strong> is a <a title="Algorithm" href="http://en.wikipedia.org/wiki/Algorithm">deterministic procedure</a> that takes an arbitrary block of <a title="Data" href="http://en.wikipedia.org/wiki/Data">data</a> and returns a fixed-size <a title="Bit" href="http://en.wikipedia.org/wiki/Bit">bit</a> string, the (<strong>cryptographic</strong>) <strong>hash value</strong>, such that an accidental or intentional change to the data will change the hash value. The data to be encoded is often called the &#8220;message&#8221;, and the hash value is sometimes called the <strong>message digest</strong> or simply <strong>digest</strong>.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2009/12/security-article-password-security-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-To: Use the PHP Data Objects class to access your database</title>
		<link>http://www.michielvdvelde.nl/2009/12/how-to-use-the-php-data-objects-class-to-access-your-database/</link>
		<comments>http://www.michielvdvelde.nl/2009/12/how-to-use-the-php-data-objects-class-to-access-your-database/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 14:48:28 +0000</pubDate>
		<dc:creator>Michiel</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.michielvdvelde.nl/?p=64</guid>
		<description><![CDATA[If you&#8217;re a PHP developer, you are of course aware of PDO; PHP Data Objects. Or are you? PDO is the new form to communicate with databases, for example MySQL, PostgreSQL and MSSQL. When you&#8217;re using MySQL, you may be using the following methode to connect to your database: $connection = new mysqli&#40;'localhost','username','password'&#41;; Or, even [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a PHP developer, you are of course aware of PDO; PHP Data Objects. Or are you?<br />
PDO is the new form to communicate with databases, for example MySQL, PostgreSQL and MSSQL. When you&#8217;re using MySQL, you may be using the following methode to connect to your database:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or, even worse:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This of course is hopelessly outdated, and with PHP version 6 on the way, will soon be removed from the standard installed libraries. But there is a better, more Object Oriented way to connect to your database, and that is PHP Data Objects.</p>
<p><strong>What is PDO?<br />
</strong>According to <a title="php.net" href="http://www.php.net/manual/en/intro.pdo.php" target="_blank">php.net</a>:</p>
<blockquote><p>The <em>PHP Data Objects</em> (<acronym>PDO</acronym>) extension defines a lightweight, consistent interface    for accessing databases in PHP. Each database driver that    implements the PDO interface can expose database-specific    features as regular extension functions. Note that you cannot    perform any database functions using the PDO extension by    itself; you must use a <a href="http://www.php.net/manual/en/pdo.drivers.php" target="_blank">database-specific    PDO driver</a> to access a database server.</p>
<p>PDO provides a <em>data-access</em> abstraction layer, which    means that, regardless of which database you&#8217;re using, you use the same    functions to issue queries and fetch data.  PDO does    <em>not</em> provide a <em>database</em> abstraction; it doesn&#8217;t rewrite SQL or emulate missing features.  You    should use a full-blown abstraction layer if you need that facility.</p>
<p>PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0;    PDO requires the new OO features in the core of PHP 5, and so will not    run with earlier versions of PHP.</p></blockquote>
<p><strong>Connecting to your MySQL database</strong><br />
So, how does one use it? Below is an example for MySQL (other databases might require a slightly different approach):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$connectionString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql:host=localhost;dbname=database&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pdo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span><span style="color: #000088;">$connectionString</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now you can use the <em>$pdo</em> variable to do things, e.g.:</p>
<p><strong>Retrieve information from tables</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM table&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is how you can read data from your database tables. Note that you don&#8217;t use the <em>while</em> loop and the <em>fetch_num</em> or <em>fetch_assoc </em>(or similar) in this case, but a <em>foreach </em>loop. You can access the field values as you would in an ordinary array.</p>
<p><strong>Queries that don&#8217;t return anything: the wrong way to do it<br />
</strong>For queries that don&#8217;t return anything, for example <em>INSERT</em> and <em>UPDATE</em> queries, PDO provides the <em>exec</em> method. This method returns the amount of rows affected (if any) by the query. Using it is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO 'table' (id, value) VALUES ('1','this is the value')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this method is susceptible to <a title="SQL injection on Wikipedia" href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL injections</a>. Therefore, the PDO class gives us another method to insert or alter information in/from the database: <strong>prepared statements<em>. </em></strong>A prepared statement is SQL injection safe and the right way to do things, especially if you need to insert or alter user submitted information. Here an example of how to use prepared statements:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$stmt</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO table (name, value) VALUES (:name, :value)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bindParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':value'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// insert a row</span>
<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'one'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stmt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is a safe way to insert or update data in your database. Of course you can use prepared statements with SELECT queries as well.</p>
<p><strong>The Basics<br />
</strong>This provides you with the basics to select, insert and update data from.to your MySQL database. Later I will expand on this subject, and dive into the more complex possibilities of PDO, as wel as how to access other databases than MySQL.</p>
<p><strong>Related Links<br />
</strong></p>
<ul>
<li><a title="PDO op php.net" href="http://php.net/manual/en/book.pdo.php" target="_blank">PDO on php.net</a></li>
<li><a title="SQL injection on Wikipedia" href="http://en.wikipedia.org/wiki/SQL_injection" target="_blank">SQL Injection on Wikipedia</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.michielvdvelde.nl/2009/12/how-to-use-the-php-data-objects-class-to-access-your-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
