<?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>Jason Ashdown &#187; PHP</title>
	<atom:link href="http://www.jasonashdown.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonashdown.co.uk</link>
	<description>There&#039;s no place like 127.0.0.1</description>
	<lastBuildDate>Thu, 22 Dec 2011 11:40:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Solved: Debian Squeeze + Nginx + PHP5-FPM</title>
		<link>http://www.jasonashdown.co.uk/2011/09/solved-debian-squeeze-nginx-php5-fpm/</link>
		<comments>http://www.jasonashdown.co.uk/2011/09/solved-debian-squeeze-nginx-php5-fpm/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 00:24:47 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Waffle News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Debian Squeeze]]></category>
		<category><![CDATA[Nginx]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=228</guid>
		<description><![CDATA[After tiresomely testing the config &#8211; I eventually got it to work. Once you know how it&#8217;s really easy but I kept getting a &#8220;502 Bad Gateway&#8221; error that confused me. Benefits of sockets over TCP: Faster connection over sockets &#8230; <a href="http://www.jasonashdown.co.uk/2011/09/solved-debian-squeeze-nginx-php5-fpm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After tiresomely testing the config &#8211; I eventually got it to work.</p>
<p>Once you know how it&#8217;s really easy but I kept getting a &#8220;502 Bad Gateway&#8221; error that confused me.</p>
<p>Benefits of sockets over TCP:</p>
<ul>
<li>Faster connection over sockets than TCP; 20% boost</li>
<li>More secure as sockets are harder to break their permissions</li>
</ul>
<p>Anyway, here&#8217;s what you need to do. All config locations are the defaults installed by Debian Squeeze.</p>
<p>Add Dotdeb&#8217;s sources in your Debian <em>/etc/apt/source.list</em></p>
<pre class="brush: plain; title: ; notranslate">
## PHP5-FPM
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
</pre>
<p>Then install php5-fpm:</p>
<pre class="brush: plain; title: ; notranslate">
apt-get update
apt-get install php5-fpm
</pre>
<p>Change the settings in <em>/etc/php5/fpm/php-fpm.conf</em></p>
<pre class="brush: plain; title: ; notranslate">
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
daemonize = yes
include=/etc/php5/fpm/pool.d/*.conf
</pre>
<p>Recommended settings in <em>/etc/php5/fpm/pool.d/www.conf</em></p>
<pre class="brush: plain; title: ; notranslate">
;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0666

user = www-data
group = www-data

php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = 0
php_admin_value[memory_limit] = 128M
php_admin_value[date.timezone] = Europe/London
</pre>
<p>Start/Restart Nginx and PHP5-FPM and voila</p>
<pre class="brush: plain; title: ; notranslate">
/etc/init.d/nginx restart
/etc/init.d/php5-fpm start
</pre>
<p>Everything should be running smoothly. Enjoy your new faster server!</p>
<p>Thanks to the people below who wrote about it first.</p>
<ul>
<li><a href="http://www.kutukupret.com/2010/10/26/how-to-make-php-fpm-listen-on-both-tcp-and-unix-socket/" target="_blank">http://www.kutukupret.com/2010/10/26/how-to-make-php-fpm-listen-on-both-tcp-and-unix-socket/</a></li>
<li><a href="http://www.kutukupret.com/2010/10/26/how-to-make-php-fpm-listen-on-both-tcp-and-unix-socket/" target="_blank">http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian</a></li>
<li><a href="http://norbyit.se/blog/2011/01/configuring-php-fpm/" target="_blank">http://norbyit.se/blog/2011/01/configuring-php-fpm/</a></li>
<li><a href="http://andreas-lehr.com/blog/archives/491-nginx-wordpress-php-fpm-on-debian-squeeze.html" target="_blank">http://andreas-lehr.com/blog/archives/491-nginx-wordpress-php-fpm-on-debian-squeeze.html</a></li>
<li><a href="http://www.webhostingtalk.com/showthread.php?t=1025286" target="_blank">http://www.webhostingtalk.com/showthread.php?t=1025286</a></li>
<li><a href="http://www.kutukupret.com/2010/10/26/how-to-make-php-fpm-listen-on-both-tcp-and-unix-socket/" target="_blank">http://www.kutukupret.com/2010/10/26/how-to-make-php-fpm-listen-on-both-tcp-and-unix-socket/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2011/09/solved-debian-squeeze-nginx-php5-fpm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create your first Twitter App with Zend Framework</title>
		<link>http://www.jasonashdown.co.uk/2011/02/create-your-first-twitter-app/</link>
		<comments>http://www.jasonashdown.co.uk/2011/02/create-your-first-twitter-app/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 23:50:46 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=92</guid>
		<description><![CDATA[I finally got round to writing my first Twitter App using Zend OAuth. Here are my tips and explanation to getting your Twitter App up and running. Getting Started Register at http://dev.twitter.com/ and create your first App. You can change &#8230; <a href="http://www.jasonashdown.co.uk/2011/02/create-your-first-twitter-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I finally got round to writing my first <a href="http://dev.twitter.com/">Twitter App</a> using <a href="http://framework.zend.com/manual/en/zend.oauth.introduction.html">Zend OAuth</a>.</p>
<p>Here are my tips and explanation to getting your Twitter App up and running.</p>
<h3>Getting Started</h3>
<p>Register at <a href="http://dev.twitter.com/">http://dev.twitter.com/</a> and create your first <em>App</em>. You can change all the settings at any time, so don&#8217;t worry about getting them wrong.</p>
<h3>Setting Up the Twitter App</h3>
<p>Authorise a <em>Domain URL</em>, you can even use localhost for testing purposes.</p>
<p>It is <span style="text-decoration: underline;">important</span> you set the <em>Callback URL</em> otherwise you can&#8217;t use the <em>Browser App</em> option and your OAuth will <strong>fail</strong>.</p>
<p>Quickly access your App&#8217;s details at <a href="http://twitter.com/oauth">http://twitter.com/oauth</a>.</p>
<p>When coding with Zend OAuth, read the <a href="http://framework.zend.com/manual/en/zend.oauth.introduction.html">documentation</a> carefully!<br />
It has <em>everything</em> you need.</p>
<h3>My Mistake</h3>
<p>I did not understand how to grab the <em>Access Token</em>. Reason? It&#8217;s a two part process. Requesting, then <em>Receiving</em>.</p>
<h3>The Code</h3>
<p>Here is a working example of a <em>Request Token</em> with <a href="http://framework.zend.com/manual/en/zend.oauth.introduction.html">Zend OAuth</a> and <em>your</em> Twitter App&#8217;s <em>Consumer Key</em> and <em>Consumer Secret</em>.</p>
<p>(Note the keys used are the ones from Zend&#8217;s Article)</p>
<pre class="brush: php; title: ; notranslate">
$config = array(
'callbackUrl' =&gt; 'http://example.com/callback.php',
'siteUrl' =&gt; 'http://twitter.com/oauth',
'consumerKey' =&gt; 'gg3DsFTW9OU9eWPnbuPzQ',
'consumerSecret' =&gt; 'tFB0fyWLSMf74lkEu9FTyoHXcazOWpbrAjTCCK48A'
);
$consumer = new Zend_Oauth_Consumer($config);

// fetch a request token
$token = $consumer-&gt;getRequestToken();

// persist the token to storage
$_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);

// redirect the user
$consumer-&gt;redirect();
</pre>
<h3>Steps you must do:</h3>
<ol>
<li>Use the <em>Callback URL</em> to receive the <em>Access Token</em></li>
<li>Store the <em>Request Token</em> in a $_SESSION</li>
<li>Follow the <a href="http://framework.zend.com/manual/en/zend.oauth.introduction.html"><em>getAccessToken()</em></a> example and store this in a $_SESSION or Database (recommended)</li>
</ol>
<h3>Why store the <em>Access Token</em> in a Database?</h3>
<p>The best thing about the <em>Access Token</em> is that once you&#8217;ve successfully requested one, it never expires!</p>
<p>So save the hassle of requesting a new token and use it throughout your website. Great thing is, it can&#8217;t be compromised!</p>
<p>Without the the <em>Consumer Key</em> and <em>Consumer Secret</em>, you can&#8217;t hijack the users account for malicious purposes.</p>
<p>Please leave a comment if you want me to write another article about how to implement the example into your scripts or maybe I&#8217;ll update this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2011/02/create-your-first-twitter-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weekly Round Up: Issue 1</title>
		<link>http://www.jasonashdown.co.uk/2010/02/weekly-round-up-issue-1/</link>
		<comments>http://www.jasonashdown.co.uk/2010/02/weekly-round-up-issue-1/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 12:34:33 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[Tech News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=69</guid>
		<description><![CDATA[I often hunt around on the internet for the latest information to do with Web Development. Most of the time it goes to my Twitter but I thought it would be great if I could start logging a collection of &#8230; <a href="http://www.jasonashdown.co.uk/2010/02/weekly-round-up-issue-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I often hunt around on the internet for the latest information to do with Web Development. Most of the time it goes to my Twitter but I thought it would be great if I could start logging a collection of the best ones I read.</p>
<p>So if you enjoy keeping up with the latest trends, I hope you enjoy my information bites!</p>
<p>HTML5 won&#8217;t save the web<br />
<a href="http://gizmodo.com/5461711/giz-explains-why-html5-isnt-going-to-save-the-internet">http://gizmodo.com/5461711/giz-explains-why-html5-isnt-going-to-save-the-internet</a></p>
<p>Facebook develop faster PHP<br />
<a href="http://www.neowin.net/news/facebook-unveils-hiphop-for-php-039source-code-transformer039">http://www.neowin.net/news/facebook-unveils-hiphop-for-php-039source-code-transformer039</a></p>
<p>IE8 now &#8220;most popular&#8221; version of IE<br />
<a href="http://www.neowin.net/news/ie8-is-now-the-world039s-most-used-browser">http://www.neowin.net/news/ie8-is-now-the-world039s-most-used-browser</a></p>
<p>Zend Framework 1.10 Released (and now with versioned documentation!)<br />
<a href="http://devzone.zend.com/article/11727-Zend-Framework-1.10.0-STABLE-Released">http://devzone.zend.com/article/11727-Zend-Framework-1.10.0-STABLE-Released</a></p>
<p>PHP hates integers (64 bit)<br />
<a href="http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/">http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2010/02/weekly-round-up-issue-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Mantis: The Bug Tracking Tool!</title>
		<link>http://www.jasonashdown.co.uk/2008/10/php-mantis-the-bug-tracking-tool/</link>
		<comments>http://www.jasonashdown.co.uk/2008/10/php-mantis-the-bug-tracking-tool/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 09:27:05 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Bug Tracking]]></category>
		<category><![CDATA[organising]]></category>
		<category><![CDATA[Todo List]]></category>
		<category><![CDATA[Trac]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=38</guid>
		<description><![CDATA[For those budding PHP developers out there, you want to run your eyes over this! http://www.mantisbt.org/ Mantis is a free Bug Tracking tool like Trac but without the SVN fuctionality. Why is this useful? There are several reasons. It&#8217;s a &#8230; <a href="http://www.jasonashdown.co.uk/2008/10/php-mantis-the-bug-tracking-tool/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-49" style="margin: 10px;" title="Mantis Bug Tracking Tool" src="http://www.jasonashdown.co.uk/wp-content/uploads/2008/11/mantis_logo.gif" alt="" width="242" height="102" />For those budding PHP developers out there, you want to run your eyes over this!</p>
<p><a href="http://www.mantisbt.org/" target="_blank">http://www.mantisbt.org/</a></p>
<p><strong>Mantis</strong> is a free Bug Tracking tool like <strong>Trac</strong> but without the SVN fuctionality.</p>
<p>Why is this useful? There are several reasons.</p>
<p>It&#8217;s a quick and easy way to log issues for any type of project. Even if it&#8217;s a simple &#8220;todo&#8221; list for a small job, its a quick and easy. Without the mess of SVN.</p>
<p><span id="more-38"></span></p>
<p>Sometimes you simply just won&#8217;t have access to SVN in your work place, so this makes it ideal replacement for keeping yourself on target. I plan to use it on my next project to see if it can really change the way I work.</p>
<h3>Other popular Bug tracking tools</h3>
<ul>
<li><strong>Trac</strong> <a href="http://trac.edgewall.org/">http://trac.edgewall.org/</a></li>
</ul>
<p>If you can suggest any other useful tracking software, I shall add it to the list above. Happy coding :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2008/10/php-mantis-the-bug-tracking-tool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Validation Class for Forms</title>
		<link>http://www.jasonashdown.co.uk/2008/08/php-validation-class-for-forms/</link>
		<comments>http://www.jasonashdown.co.uk/2008/08/php-validation-class-for-forms/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 22:50:52 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=27</guid>
		<description><![CDATA[Just to top off my daily posts, I have been perfecting a PHP Validation class over the past few months. At work I tend to do a lot of registration forms for competitions, subscriptions, newsletters, contact forms etc. So I &#8230; <a href="http://www.jasonashdown.co.uk/2008/08/php-validation-class-for-forms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just to top off my daily posts, I have been perfecting a PHP Validation class over the past few months.</p>
<p>At work I tend to do a lot of registration forms for competitions, subscriptions, newsletters, contact forms etc.</p>
<p>So I went to the trouble of creating a very quick and easy validation class that I could include into my projects at a drop of a hat. Inspired by <a title="CodeIgniter, PHP framework" href="http://codeigniter.com" target="_blank">CodeIgniters</a> validation class, it has very similar features. Including helper functions.</p>
<p>It&#8217;s even UTF-8 friendly (except for the email function). Please feel free to <a href="http://www.jasonashdown.co.uk/downloads/validation-0.2j.zip">download</a> and test it out yourself.<span id="more-27"></span></p>
<p>Here is a dump of the code:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/************************************************************
  Validation Class
  Author: Jason Ashdown
  Updated: 12:12 24/07/2008
  Version 0.2j

 --------------------------------------------------------
 Change Log:-
 v0.2j - Added 'decode' function to form helpers. To help
		 pass UTF-8 characters back to a form from the DB.
 v0.2h - Removed 'spaces' from the regexp strings
 v0.2g - Email address function is now in compliant
		 with RFC 2822
 v0.2f - Added $masks for allErrors to be more
		 user-friendly, updated loop_clean to use
		 htmlspecialchars and supports UTF-8
 v0.2e - Fixed allErrors() to include wrappers
 v0.2d - Changed &quot;required&quot; to check for empty
		 strings properly
 v0.2c - Added &quot;not_equal&quot; and &quot;selected&quot; functions
 v0.2b - Tidied comments; fixed email mx check
 v0.2a - Added loop_clean (multi-array sanitiser)
 V0.2 - Added new helper functions (label, check)
 - - -
 v0.1 - Initial Release
*************************************************************/

class validateForm
{
	var $input = array();
	var $error = array();
	var $error_wrapper;
	var $pass;

	// You can call the validated inputs directly from this class
	// when you come to inserting them into the db, e.g.
	// $form = new validateForm($_POST);
	// $form-&gt;input['fullname']; etc...

	function validateForm($input=array()) // Yes, post the the whole $_POST/$_GET array into the function
	{
		$this-&gt;input = $input; // Clone form inputs array into here

		$this-&gt;pass = true; // Flag changes if theres an error

		// Config
		$this-&gt;error_wrapper['start'] = &quot;&lt;br /&gt;&lt;span class=\&quot;error\&quot;&gt;&quot;;
		$this-&gt;error_wrapper['end'] = &quot;&lt;/span&gt;&quot;;

		// Sanitise our arrays
		$this-&gt;loop_clean($this-&gt;input);
	}

	//
	// We can even perform some security checks here if we wish
	//
	function loop_clean(&amp;$data)
	{
		foreach ($data as $key =&gt; $value)
		{
			if ( !is_array($value) )
			{
				// Well formatted string; PHP4 requires &quot;stripslashes&quot; on all input fields
				$data[$key] = trim(htmlspecialchars(strip_tags(stripslashes($value)), ENT_QUOTES, 'UTF-8'));
			}
			else
			{
				$this-&gt;loop_clean($value);
				$data[$key] = $value;
			}
		}
	}

/************************************/
/* Error Functions                  */
/************************************/

	// Set error
	function error($item, $desc)
	{
		$this-&gt;pass = false;
		$this-&gt;error[$item] .= $desc.&quot; &quot;; // Append multiple error messages
	}

	// Return the error
	function showError($item)
	{
		return $this-&gt;error_wrapper['start'].trim($this-&gt;error[$item]).$this-&gt;error_wrapper['end'];
	}

	function allErrors($masks=array())
	{
		foreach ( $this-&gt;error as $key =&gt; $value )
		{
			// Mask field names with more appropriate User friendly names
			$key = $masks[$key] != '' ? $masks[$key] : $key;
			echo $this-&gt;error_wrapper['start'].&quot;&lt;b&gt;&quot;.ucfirst($key).&quot;&lt;/b&gt;: &quot;.trim($value).$this-&gt;error_wrapper['end'];
		}
	}

/************************************/
/* Debugging                        */
/************************************/

	function showInputs()
	{
		print_r($this-&gt;input);
	}

/************************************/
/* Validation Functions             */
/************************************/

	function not_equal($string, $field)
	{
		if ( is_string($string) )
		{
			if ($string == $this-&gt;input[$field])
			{
				$msg = &quot;You must select a different option other than \&quot;$string\&quot;&quot;;
				$this-&gt;error($field, $msg);
				return false;
			}
			return true;
		}
		return false;
	}

	function min_length($min=0, $field)
	{
		if( strlen($this-&gt;input[$field]) &lt; (int) $min )
		{
			$msg = &quot;This field cannot be shorter than $min characters.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function max_length($max=0, $field)
	{
		if ( strlen($this-&gt;input[$field]) &gt; (int) $max )
		{
			$msg = &quot;This field cannot be longer than $max characters.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function alpha($field)
	{
		if ( !preg_match(&quot;/^([a-z])+$/i&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;This field can only contain letters (A-Z). No foreign characters allowed.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	// Double-barrel names and marital status will require this
	function alpha_dotdash($field)
	{
		if ( !preg_match(&quot;/^([a-z\-\.])+$/i&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;This field can only contain characters (A-Z-.). No foreign characters allowed.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	// Useful for Addresses or fields that may contain unusual but still valid chars
	function alpha_special($field)
	{
		if ( !preg_match(&quot;/^([a-z0-9\-+\.,_='\&quot;@#])+$/i&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;This field has illegal characters. You can use letters, numbers and (._-+='\&quot;@#).&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function numeric($field)
	{
		if ( !preg_match(&quot;/^[\-+]?[0-9]*\.?[0-9]+$/&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;This field must contain only numbers.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function alpha_numeric($field)
	{
		if( !preg_match(&quot;/^([a-z0-9])+$/i&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;This field can only contain letters and numbers.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function required($field)
	{
		if ( !isset($this-&gt;input[$field]) OR $this-&gt;input[$field] == '' )
		{
			$this-&gt;error($field, 'This field is required.');
			return false;
		}
		elseif ( is_array($this-&gt;input[$field]) )
		{
			$this-&gt;error($field, 'This is an array and won\'t be passed.');
			return false;
		}
		return true;
	}

/************************************/
/* Alias Functions                  */
/************************************/

	function fullname($field, $req=true)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		return $this-&gt;alpha_dotdash($field);
	}

	function address($field, $req=true)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		return $this-&gt;alpha_special($field);
	}

	function telephone($field, $req=true)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		if ( $this-&gt;numeric($field) AND $this-&gt;min_length(11, $field) AND $this-&gt;max_length(14, $field) )
		{
			return true;
		}

		return false;
	}

	function mobile($field, $req=true)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		return $this-&gt;telephone($field);
	}

	function postcode($field, $req=true)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		if ( !preg_match(&quot;/^[a-zA-Z]{1,3}[0-9]{1,3} [0-9]{1}[a-zA-Z]{2}$/i&quot;, $this-&gt;input[$field]) )
		{
			$msg = &quot;Postcode must follow the format of \&quot;XX1 1XX\&quot;.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}
		return true;
	}

	function email($field, $req=true, $mx_records=false)
	{
		if ( $req == true AND !$this-&gt;required($field) )
			return false;

		// Function from: http://www.ilovejackdaniels.com/php/email-address-validation/
		// Complies with the email address specification guidelines: RFC 2822

		// First, we check that there's one @ symbol, and that the lengths are right
		if (!ereg(&quot;^[^@]{1,64}@[^@]{1,255}$&quot;, $this-&gt;input[$field]))
		{
			// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
			$msg = &quot;Your email address is the wrong length.&quot;;
			$this-&gt;error($field, $msg);
			return false;
		}

		// Split it into sections to make life easier
		$email_array = explode(&quot;@&quot;, $this-&gt;input[$field]);
		$local_array = explode(&quot;.&quot;, $email_array[0]);

		for ($i = 0; $i &lt; sizeof($local_array); $i++)
		{
			if (!ereg(&quot;^(([A-Za-z0-9!#$%&amp;amp;amp;amp;amp;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&amp;amp;amp;amp;amp;'*+/=?^_`{|}~\.-]{0,63})|(\&quot;[^(\\|\&quot;)]{0,62}\&quot;))$&quot;, $local_array[$i]))
			{
				$msg = &quot;The first part of your email is malformed.&quot;;
				$this-&gt;error($field, $msg);
				return false;
			}
		}

		if (!ereg(&quot;^\[?[0-9\.]+\]?$&quot;, $email_array[1])) // Check if domain is IP. If not, it should be valid domain name
		{
			$domain_array = explode(&quot;.&quot;, $email_array[1]);
			if (sizeof($domain_array) &lt; 2)
			{
				$msg = &quot;Your email doesn't have a valid domain.&quot;;
				$this-&gt;error($field, $msg);
				return false; // Not enough parts to domain
			}

			for ($i = 0; $i &lt; sizeof($domain_array); $i++)
			{
				if (!ereg(&quot;^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$&quot;, $domain_array[$i]))
				{
					$msg = &quot;Your email doesn't have a valid domain.&quot;;
					$this-&gt;error($field, $msg);
					return false;
				}
			}
		}

		// Check online to see if this is a real email host!
		if ( $mx_records != false )
		{
			$host = $email_array[1]; //The whooole domain

			getmxrr($host, $mxhosts);
			if ( count($mxhosts) &lt; 1 )
			{
				$msg = &quot;There is no email host associated with your email. This probably means its fake.&quot;;
				$this-&gt;error($field, $msg);
				return false;
			}
		}

		return true;
	}

/************************************/
/* Helper Functions                 */
/************************************/

	function decode($field)
	{
		return html_entity_decode($this-&gt;input[$field]);
	}

	function label($text, $id)
	{
		return &quot;&lt;label for=\&quot;$id\&quot;&gt;$text&lt;/label&gt;&quot;;
	}

	function check($field, $value, $default=false)
	{
		if ( $default == true AND empty($this-&gt;input[$field]) )
			return 'checked=&quot;checked&quot;';

		return $this-&gt;input[$field] == $value ? 'checked=&quot;checked&quot;' : '';
	}

	function selected($field, $value, $default=false)
	{
		if ( $default == true AND empty($this-&gt;input[$field]) )
			return 'selected=&quot;selected&quot;';

		return $this-&gt;input[$field] == $value ? 'selected=&quot;selected&quot;' : '';
	}
}

/*
Example:

You can just edit $this-&gt;error_wrapper['start'] AND $this-&gt;error_wrapper['end'] to make the errors display how you want.
*/

if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
	$form = new validateForm($_POST);

	$form-&gt;required('firstname');
	$form-&gt;required('lastname');
	$form-&gt;mobile('mobile');
	$form-&gt;email('email', true); // Validate email AND make it required
	$form-&gt;required('t-and-c'); // Terms &amp;amp;amp;amp;amp; Conditions

	if ( $form-&gt;pass == true )
	{
		// Insert data into DB ...
		echo &quot;Success&quot;;
	}
}
else
{
	$form = new validateForm();
}
?&gt;

&lt;div class=&quot;error&quot;&gt;
&lt;?php

// Masks are used if you have an unfriendly named field that may cause the user confusion.
// You just specify the names and the fields in the array with the text you want to replace it with.
$masks = array(
't-and-c' =&gt; 'Terms &amp;amp;amp;amp;amp; Conditions');

$form-&gt;allErrors($masks);
?&gt;
&lt;/div&gt;

&lt;form method=&quot;post&quot;&gt;

&lt;p&gt;*First Name: &lt;input type=&quot;text&quot; name=&quot;firstname&quot; value=&quot;&lt;?php echo $form-&gt;input['firstname'];?&gt;&quot; maxlength=&quot;80&quot; /&gt;
&lt;?php
// Show inidividual errors
echo $form-&gt;showError('firstname');
?&gt;
&lt;/p&gt;

&lt;p&gt;*Last Name: &lt;input type=&quot;text&quot; name=&quot;lastname&quot; value=&quot;&lt;?php echo $form-&gt;input['lastname'];?&gt;&quot; maxlength=&quot;80&quot; /&gt;&lt;/p&gt;
&lt;?php
// OR Specify your own error message
if ( $form-&gt;showError('lastname') )
{
	echo 'You must fill in the &quot;Last Name&quot; field.';
}
?&gt;

&lt;p&gt;Mobile: &lt;input type=&quot;text&quot; name=&quot;mobile&quot; value=&quot;&lt;?php echo $form-&gt;input['mobile'];?&gt;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;*Email: &lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;&lt;?php echo $form-&gt;input['email'];?&gt;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Comment: &lt;textarea name=&quot;comment&quot;&gt;
&lt; ?php
// If you ever send data that has UTF-8 in it, you can use the decode helper if retrieving it from a DB
echo $form-&gt;decode('comment');

?&gt;&lt;/textarea&gt;&lt;/p&gt;

&lt;p&gt;&lt;input type=&quot;checkbox&quot; name=&quot;t-and-c&quot; id=&quot;t-and-c&quot; value=&quot;true&quot; &lt;?php echo $form-&gt;check('t-and-c', true);?&gt;/&gt; &lt;?php echo $form-&gt;label('Terms and Conditions*' ,'t-and-c');?&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;* Required&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Send&quot; /&gt;&lt;/p&gt;

&lt;/form&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2008/08/php-validation-class-for-forms/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Lytebox with javascript Exif Data</title>
		<link>http://www.jasonashdown.co.uk/2008/08/lytebox-with-javascript-exif-data/</link>
		<comments>http://www.jasonashdown.co.uk/2008/08/lytebox-with-javascript-exif-data/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 22:16:43 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[Waffle News]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[EXIF]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Gallery]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lightbox]]></category>
		<category><![CDATA[Lytebox]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Photos]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=21</guid>
		<description><![CDATA[Recently I had to integrate a photo gallery for one of my work projects Sony Alpha, a new digital SLR camera from Sony. My task was to display both the Exif data and the image at the same time. For &#8230; <a href="http://www.jasonashdown.co.uk/2008/08/lytebox-with-javascript-exif-data/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-42" style="margin: 10px;" title="Lytebox with Exif: Screenshot" src="http://www.jasonashdown.co.uk/wp-content/uploads/2008/11/lytebox_exif_screenshot-300x280.jpg" alt="" width="300" height="280" /></p>
<p>Recently I had to integrate a photo gallery for one of my work projects <a title="Sony Alpha Digital Camera" href="http://sony.dcmag.co.uk" target="_blank">Sony Alpha</a>, a new digital SLR camera from Sony. My task was to display both the Exif data and the image at the same time.</p>
<p>For this project I had to create something new which I haven&#8217;t found on the internet before. It uses the popular <a title="Popular Light Box adaption" href="http://dolem.com/lytebox/" target="_blank">Lytebox</a> extension (a flavour of the popular <a href="http://www.huddletogether.com/projects/lightbox2/" target="_blank">Lightbox 2</a> javascript library) combined with a new javascript plugin that gathers <a href="http://blog.nihilogic.dk/2008/05/reading-exif-data-with-javascript.html" target="_blank">Exif Data</a> for photos via javascript with AJAX.<span id="more-21"></span></p>
<p>Other conventional methods tend to use a PHP file that grabs the exif data and switches between the data in a tab, but this is the first time I have seen of combining Lytebox with the javascript Exif plugin.</p>
<p>This version of Lytebox actually displays the exif data at the same time as the image. It took me many days to actually make it work but I finally managed it. It still doesn&#8217;t work in Opera or Safari but it does work for Firefox and IE.</p>
<p>I will bundle the files into a download so that people can use it and will attach it to this post, but I am very impressed that I managed to create the first javascript gallery that uses javascript to extract the Exif data from a photograph.</p>
<h2><strong>IMPORTANT UPDATE &#8211; 2008 / 10 /28<br />
</strong></h2>
<p>I have updated this post to include some <a href="http://www.jasonashdown.co.uk/lytebox_with_exif/">Online Examples</a> with the plugin in action! You can also now <a href="http://www.jasonashdown.co.uk/downloads/lytebox_with_exif.zip">Download</a> the files. I am sorry it has taken this long to get the files to you guys but it was finding the time to do it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2008/08/lytebox-with-javascript-exif-data/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CL Auth reaches maturity with v0.2</title>
		<link>http://www.jasonashdown.co.uk/2008/07/cl-auth-reaches-maturity-with-v02/</link>
		<comments>http://www.jasonashdown.co.uk/2008/07/cl-auth-reaches-maturity-with-v02/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 11:51:41 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CL Auth]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=12</guid>
		<description><![CDATA[CL Auth is finally in round 2 of BETA testing. BETA v0.2 offers better optimisation, new functions, better documentation and easier customisation. It also quashes some known bugs from the previous BETA. Download or view the Documentation online.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-50" style="margin: 10px;" title="CL Auth" src="http://www.jasonashdown.co.uk/wp-content/uploads/2008/11/cl_auth_logo.png" alt="" width="216" height="80" />CL Auth is finally in round 2 of BETA testing. BETA v0.2 offers better optimisation, new functions, better documentation and easier customisation. It also quashes some known bugs from the previous BETA.</p>
<p><a href="http://www.jasonashdown.co.uk/downloads/CL_Auth_BETA-v0.2.zip">Download</a> or view the <a href="http://www.jasonashdown.co.uk/cl_auth_doc/">Documentation online</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2008/07/cl-auth-reaches-maturity-with-v02/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CL Auth Documentation</title>
		<link>http://www.jasonashdown.co.uk/2008/06/cl-auth-documentation/</link>
		<comments>http://www.jasonashdown.co.uk/2008/06/cl-auth-documentation/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 20:08:32 +0000</pubDate>
		<dc:creator>Jason Ashdown</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CL Auth]]></category>
		<category><![CDATA[CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.jasonashdown.co.uk/?p=6</guid>
		<description><![CDATA[I&#8217;ve published the first draft of the CL Auth Documentation online. I have placed it on this website so everybody can access it.]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-50" style="margin: 10px;" title="CL Auth" src="http://www.jasonashdown.co.uk/wp-content/uploads/2008/11/cl_auth_logo.png" alt="" width="216" height="80" />I&#8217;ve published the first draft of the <a href="http://www.jasonashdown.co.uk/cl_auth_doc/">CL Auth Documentation online</a>. I have placed it on this website so everybody can access it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonashdown.co.uk/2008/06/cl-auth-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

