<?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>david winter</title>
	<atom:link href="http://davidwinter.me.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidwinter.me.uk</link>
	<description>you were expecting someone else?</description>
	<lastBuildDate>Tue, 02 Mar 2010 21:40:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing MySQL for PHP with MacPorts</title>
		<link>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/</link>
		<comments>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 13:38:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=162</guid>
		<description><![CDATA[In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a Wordpress theme and plugin on my local machine. Here are the few steps I used:



sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u _mysql mysql_install_db5
sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ 
sudo chown -R _mysql:_mysql [...]]]></description>
			<content:encoded><![CDATA[<p>In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a Wordpress theme and plugin on my local machine. Here are the few steps I used:</p>

<p><span id="more-162"></span></p>

<pre><code>sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u _mysql mysql_install_db5
sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/run/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/log/mysql5/
</code></pre>

<p>I then add the following aliases to make it easy to start, stop and restart MySQL:</p>

<pre><code>mate ~/.bashrc

alias mysql-start="sudo /opt/local/share/mysql5/mysql/mysql.server start"
alias mysql-restart="sudo /opt/local/share/mysql5/mysql/mysql.server restart"
alias mysql-stop="sudo /opt/local/share/mysql5/mysql/mysql.server stop"

source ~/.profile
</code></pre>

<p>You can then use the following to start MySQL:</p>

<pre><code>mysql-start
</code></pre>

<p><em>Note: I had errors when I first tried starting MySQL. This was because I&#8217;d installed a version of MySQL previously from the official site and it was conflicting. Removing the old version of MySQL did the trick &#8211; instructions <a href="http://tomkeur.net/39/how-to-remove-mysql-completely-mac-os-x-leopard.html">here</a>.</em></p>

<p>When you start the server, it&#8217;s best to set the <code>root</code> user password:</p>

<pre><code>mysqladmin5 -u root password mysupersecretpassword
</code></pre>

<p>Then to setup PHP to work with MySQL:</p>

<pre><code>sudo port install php5-mysql
</code></pre>

<p>Then update the php.ini file:</p>

<pre><code>sudo nano /opt/local/etc/php5/php.ini
</code></pre>

<p>And ensure this line is in there:</p>

<pre><code>mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
</code></pre>

<p>Restart Apache, and then you&#8217;re all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache, PHP and MongoDB on Mac OS X 10.6 Snow Leopard</title>
		<link>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/</link>
		<comments>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 13:12:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=152</guid>
		<description><![CDATA[MongoDB (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database.

There&#8217;s a lot of buzz brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the Xcode developer [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database.</p>

<p>There&#8217;s a lot of <a href="http://delicious.com/search?p=mongodb&amp;chk=&amp;context=popular|&amp;fr=del_icio_us&amp;lc=">buzz</a> brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the <a href="[http://developer.apple.com/tools/xcode/">Xcode</a> developer tools (found on the Snow Leopard install DVD) and <a href="[http://www.macports.org/">MacPorts</a> for this to all work.</p>

<p><span id="more-152"></span></p>

<p>First, let&#8217;s install Apache:</p>

<pre><code>sudo port install apache2
</code></pre>

<p>Nice and simple. Now we can move onto PHP:</p>

<pre><code>sudo port install php5 +apache2 +pear
</code></pre>

<p>To enable PHP for Apache:</p>

<pre><code>cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
</code></pre>

<p>I like to make some alias commands for starting, restarting and stopping Apache:</p>

<pre><code>mate ~/.bashrc

alias apache-start="sudo /opt/local/apache2/bin/apachectl start"
alias apache-restart="sudo /opt/local/apache2/bin/apachectl restart"
alias apache-stop="sudo /opt/local/apache2/bin/apachectl stop"

source ~/.bashrc
</code></pre>

<p>Now we can make a few changes to the Apache config so that we can use our Sites directory:</p>

<pre><code>sudo mate /opt/local/apache2/conf/httpd.conf
</code></pre>

<p>I&#8217;m using Textmate here (<code>mate</code>), but you can use any editor you wish, like <code>nano</code>.</p>

<p>Change the <code>DocumentRoot</code>:</p>

<pre><code>DocumentRoot "/Users/davidwinter/Sites"
</code></pre>

<p>Then update the <code>&lt;Directory&gt;</code> path to the updated <code>DocumentRoot</code> path.  </p>

<pre><code>&lt;Directory "/Users/davidwinter/Sites"&gt;
</code></pre>

<p>We also want to enable <code>index.php</code> as a directory index file:</p>

<pre><code>&lt;IfModule dir_module&gt;
    DirectoryIndex index.html index.php
&lt;/IfModule&gt;
</code></pre>

<p>And then add the PHP mime type:</p>

<pre><code>&lt;IfModule mime_module&gt;
    ...
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
&lt;/IfModule&gt;
</code></pre>

<p>Now we need to setup the <code>php.ini</code> file:</p>

<pre><code>sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini

sudo mate /opt/local/etc/php5/php.ini
</code></pre>

<p>My <a href="[http://php.net/manual/en/timezones.php">timezone</a> is for London:</p>

<pre><code>date.timezone = Europe/London
</code></pre>

<p>Now we can get onto installing MongoDB (this will install the latest stable version as of time of writing &#8211; 1.2.1): </p>

<pre><code>sudo port install mongodb
</code></pre>

<p>And then the PHP MongoDB extension:</p>

<pre><code>sudo pecl install mongo
</code></pre>

<p>You&#8217;ll need to add the extension to the bottom of your <code>php.ini</code> file:</p>

<pre><code>sudo mate /opt/local/etc/php5/php.ini

extension=mongo.so
</code></pre>

<p>Now startup Apache using the <code>alias</code> created earlier:</p>

<pre><code>apache-start
</code></pre>

<p>If you create a file in your Sites directory, called <code>test.php</code>, and add the following to it:</p>

<pre><code>&lt;?php phpinfo(); ?&gt;
</code></pre>

<p>Then visit the page in your browser; <a href="http://localhost/test.php">http://localhost/test.php</a></p>

<p>You can then scroll down the page and you should see a section titled &#8216;mongo&#8217;. This means the extension is working!</p>

<p>Now we need to startup MongoDB:</p>

<pre><code>mkdir -p ~/data/db
mongod --dbpath ~/data/db/
</code></pre>

<p>Almost there, now a simple MongoDB test in PHP:</p>

<pre><code>&lt;?php
// Connect:
$connection = new Mongo();
// Select database:
$db = $connection-&gt;my_db;
// Select collection:
$films = $db-&gt;films;

$frwl = array(
    'title' =&gt; 'From Russia With Love',
    'year' =&gt; 1963,
    'actor' =&gt; 'Sean Connery'
);
// Save array to collection:
$films-&gt;insert($frwl);

$gf = array(
    'title' =&gt; 'Goldfinger',
    'year' =&gt; 1964,
    'actor' =&gt; 'Sean Connery',
    'girl' =&gt; 'Pussy Galore'
);

$films-&gt;insert($gf);

// Count documents in collection:
if ($films-&gt;count()): ?&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Title&lt;/th&gt;
        &lt;th&gt;Year&lt;/th&gt;
        &lt;th&gt;Actor&lt;/th&gt;
        &lt;th&gt;Girl&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php foreach ($films-&gt;find() as $film): ?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $film['title']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['year']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['actor']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['girl']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php endforeach; ?&gt;
&lt;/table&gt;
&lt;?php endif;
?&gt;
</code></pre>

<p>Very exciting stuff. More to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Remove startup scripts on Ubuntu</title>
		<link>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/</link>
		<comments>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:55:40 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/</guid>
		<description><![CDATA[sudo update-rc.d -f script_name remove

]]></description>
			<content:encoded><![CDATA[<pre><code>sudo update-rc.d -f script_name remove
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert git repository to mercurial</title>
		<link>http://davidwinter.me.uk/articles/2009/10/17/convert-git-repository-to-mercurial/</link>
		<comments>http://davidwinter.me.uk/articles/2009/10/17/convert-git-repository-to-mercurial/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 16:13:00 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[mercurial]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=149</guid>
		<description><![CDATA[Ensure that the mercurial convert extension is enabled:

nano ~/.hgrc


Inside that file add:

[extensions]
hgext.convert=


Save. Now do:

hg convert my-git-repo


This will create a new directory called my-git-repo-hg. This will appear empty at first, so do this:

cd my-git-repo-hg
hg checkout


All of your files will appear and you&#8217;re ready to go.
]]></description>
			<content:encoded><![CDATA[<p>Ensure that the mercurial convert extension is enabled:</p>

<pre><code>nano ~/.hgrc
</code></pre>

<p>Inside that file add:</p>

<pre><code>[extensions]
hgext.convert=
</code></pre>

<p>Save. Now do:</p>

<pre><code>hg convert my-git-repo
</code></pre>

<p>This will create a new directory called <code>my-git-repo-hg</code>. This will appear empty at first, so do this:</p>

<pre><code>cd my-git-repo-hg
hg checkout
</code></pre>

<p>All of your files will appear and you&#8217;re ready to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/10/17/convert-git-repository-to-mercurial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable PHP error logging</title>
		<link>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/</link>
		<comments>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 20:02:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/</guid>
		<description><![CDATA[In php.ini:

display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log


Make the log file, and writable by www-data:

sudo touch /var/log/php-errors.log
sudo chown www-data:www-data /var/log/php-errors.log

]]></description>
			<content:encoded><![CDATA[<p>In php.ini:</p>

<pre><code>display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log
</code></pre>

<p>Make the log file, and writable by www-data:</p>

<pre><code>sudo touch /var/log/php-errors.log
sudo chown www-data:www-data /var/log/php-errors.log
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and nginx on Ubuntu: the easy way</title>
		<link>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/</link>
		<comments>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 19:31:08 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=139</guid>
		<description><![CDATA[I&#8217;ve now changed my slice from running lighttpd to nginx. Here&#8217;s the simplest way, in around 6 commands, to get PHP up and running via FastCGI.

Install and setup

Install PHP 5:

sudo aptitude install php5-cgi


Install nginx:

sudo aptitude install nginx


Create PHP 5 FastCGI start-up script:

sudo nano /etc/init.d/php-fastcgi


Inside, put:

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
  [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve now changed my slice from running lighttpd to nginx. Here&#8217;s the simplest way, in around 6 commands, to get PHP up and running via FastCGI.</p>

<h2>Install and setup</h2>

<p>Install PHP 5:</p>

<pre><code>sudo aptitude install php5-cgi
</code></pre>

<p>Install nginx:</p>

<pre><code>sudo aptitude install nginx
</code></pre>

<p>Create PHP 5 FastCGI start-up script:</p>

<pre><code>sudo nano /etc/init.d/php-fastcgi
</code></pre>

<p>Inside, put:</p>

<pre><code>#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL
</code></pre>

<p>Make start-up script executable:</p>

<pre><code>sudo chmod +x /etc/init.d/php-fastcgi
</code></pre>

<p>Launch PHP:</p>

<pre><code>sudo /etc/init.d/php-fastcgi start
</code></pre>

<p>Launch at start-up:</p>

<pre><code>sudo update-rc.d php-fastcgi defaults
</code></pre>

<p>That&#8217;s it. All installed and ready to go.</p>

<h2>Test</h2>

<p>In your server config, add the following:</p>

<pre><code>location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
    include         fastcgi_params;
}
</code></pre>

<p>Restart nginx:</p>

<pre><code>sudo /etc/init.d/nginx restart
</code></pre>

<p>Create a file in your web root (in the example above, /var/www/nginx-default/test.php):</p>

<pre><code>&lt;?php

phpinfo();
</code></pre>

<p>Visit the page in your browser and you should see the standard PHP info page. And you&#8217;re done.</p>

<p>Source: <a href="http://tomasz.sterna.tv/2009/04/php-fastcgi-with-nginx-on-ubuntu/">Aberration</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Applescript to shutdown in 15 seconds</title>
		<link>http://davidwinter.me.uk/articles/2009/05/28/applescript-to-shutdown-in-15-seconds/</link>
		<comments>http://davidwinter.me.uk/articles/2009/05/28/applescript-to-shutdown-in-15-seconds/#comments</comments>
		<pubDate>Thu, 28 May 2009 19:25:33 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/05/28/applescript-to-shutdown-in-15-seconds/</guid>
		<description><![CDATA[set userCancelled to false

try
    set answer to display dialog "Backup complete. Shutting down in 15 seconds." giving up after 15
on error number -128
    set userCancelled to true
end try

if userCancelled then

else if gave up of answer then
    tell application "Finder"
        [...]]]></description>
			<content:encoded><![CDATA[<pre><code>set userCancelled to false

try
    set answer to display dialog "Backup complete. Shutting down in 15 seconds." giving up after 15
on error number -128
    set userCancelled to true
end try

if userCancelled then

else if gave up of answer then
    tell application "Finder"
        shut down
    end tell
end if
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/05/28/applescript-to-shutdown-in-15-seconds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authentication with CodeIgniter</title>
		<link>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/</link>
		<comments>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 17:37:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=127</guid>
		<description><![CDATA[Here&#8217;s how I do some basic authentication for a controller in CodeIgniter. It basically consists of creating a new class that extends the default Controller class. You then sub-class this on any controller that requires authentication.



Create your authentication controller in system/application/libraries and call it MY_Controller.php. It&#8217;s important that you prefix the controller name with MY_, [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how I do some basic authentication for a controller in <a href="http://codeigniter.com/">CodeIgniter</a>. It basically consists of creating a new class that extends the default <code>Controller</code> class. You then sub-class this on any controller that requires authentication.</p>

<p><span id="more-127"></span></p>

<p>Create your authentication controller in <code>system/application/libraries</code> and call it <code>MY_Controller.php</code>. It&#8217;s important that you prefix the controller name with <code>MY_</code>, or whatever you have specified <code>$config['subclass_prefix']</code> as in your configuration.</p>

<pre><code>&lt;?php

class MY_Controller extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this-&gt;load-&gt;library('session');
        if (!$this-&gt;session-&gt;userdata('loggedin'))
        {
            header('Location: /sessions/login');
        }
    }
}
</code></pre>

<p>This basically checks if the session data for <code>loggedin</code> is set to <code>true</code>. If not, it&#8217;ll redirect the user to the <code>/sessions/login</code> URL. This means we have to create a basic controller to handle the sessions.</p>

<pre><code>&lt;?php

class Sessions extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this-&gt;load-&gt;library('session');
    }

    public function login()
    {
        $this-&gt;load-&gt;view('header');
        $this-&gt;load-&gt;view('sessions/login');
        $this-&gt;load-&gt;view('footer');
    }

    public function authenticate()
    {
        $this-&gt;load-&gt;model('user', '', true);
        if ($this-&gt;user-&gt;authenticate($this-&gt;input-&gt;post('username'), $this-&gt;input-&gt;post('password')))
        {
            $this-&gt;session-&gt;set_userdata('loggedin', true);
            header('Location: /');
        }
        else
        {
            header('Location: /sessions/login');
        }
    }

    public function logout()
    {
        $this-&gt;session-&gt;unset_userdata('loggedin');
        header('Location: /');
    }
}
</code></pre>

<p>The <code>login</code> view is a basic form with fields for <code>username</code> and <code>password</code> that submits to <code>/sessions/authenticate</code>. This controller then loads the user model and checks that a user with the username and password exists. If so, it sets the session data for <code>loggedin</code> to <code>true</code> and redirects the user back to the default controller. If not, it takes the user back to the login page.</p>

<p>Then to implement the authentication in a controller, simply do:</p>

<pre><code>&lt;?php

class SecretPlace extends MY_Controller
{
...
</code></pre>

<p>It&#8217;s a good idea to <a href="http://codeigniter.com/user_guide/libraries/sessions.html">store your session data in your database</a> and encrypt your cookies with <code>$config['sess_encrypt_cookie'] = TRUE;</code> in <code>config.php</code>. That way people won&#8217;t be able to snoop around and try to trick your application into thinking they&#8217;re authenticated.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Hide GIT or SVN files with lighttpd</title>
		<link>http://davidwinter.me.uk/articles/2009/02/20/hide-git-or-svn-files-with-lighttpd/</link>
		<comments>http://davidwinter.me.uk/articles/2009/02/20/hide-git-or-svn-files-with-lighttpd/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 18:01:43 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lighttpd]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/02/20/hide-git-or-svn-files-with-lighttpd/</guid>
		<description><![CDATA[Add this to the bottom of your lighttpd.conf file:

$HTTP["url"] =~ "/\.(git&#124;svn)/" {
    url.access-deny = ( "" )
}

]]></description>
			<content:encoded><![CDATA[<p>Add this to the bottom of your <code>lighttpd.conf</code> file:</p>

<pre><code>$HTTP["url"] =~ "/\.(git|svn)/" {
    url.access-deny = ( "" )
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/02/20/hide-git-or-svn-files-with-lighttpd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick lighttpd, PHP, iMagick setup on Ubuntu 8.10 Intrepid</title>
		<link>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/</link>
		<comments>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 17:17:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/</guid>
		<description><![CDATA[Install lighttpd:

sudo aptitude install lighttpd


Install PHP and ImageMagick:

sudo aptitude install php5-common php5-dev php5-mysql php5-sqlite php5-cgi php5-curl php5-gd php-pear libmagick9-dev


Install iMagick:

sudo pecl install imagick


Press enter on prompt.

Add the following to the bottom of /etc/php5/cgi/php.ini:

extension=imagick.so


Then:

sudo lighttpd-enable-mod fastcgi
sudo /etc/init.d/lighttpd reload

]]></description>
			<content:encoded><![CDATA[<p>Install <code>lighttpd</code>:</p>

<pre><code>sudo aptitude install lighttpd
</code></pre>

<p>Install <code>PHP</code> and <code>ImageMagick</code>:</p>

<pre><code>sudo aptitude install php5-common php5-dev php5-mysql php5-sqlite php5-cgi php5-curl php5-gd php-pear libmagick9-dev
</code></pre>

<p>Install <code>iMagick</code>:</p>

<pre><code>sudo pecl install imagick
</code></pre>

<p>Press enter on prompt.</p>

<p>Add the following to the bottom of <code>/etc/php5/cgi/php.ini</code>:</p>

<pre><code>extension=imagick.so
</code></pre>

<p>Then:</p>

<pre><code>sudo lighttpd-enable-mod fastcgi
sudo /etc/init.d/lighttpd reload
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
