<?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>SickBiscuit &#187; BSD</title>
	<atom:link href="http://sickbiscuit.com/blog/category/bsd/feed/" rel="self" type="application/rss+xml" />
	<link>http://sickbiscuit.com/blog</link>
	<description>The personal blog of Steven Wilkin</description>
	<lastBuildDate>Tue, 31 Jan 2012 01:12:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP predefined variables on BSD</title>
		<link>http://sickbiscuit.com/blog/2007/04/03/php-predefined-variables-on-bsd/</link>
		<comments>http://sickbiscuit.com/blog/2007/04/03/php-predefined-variables-on-bsd/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 10:51:38 +0000</pubDate>
		<dc:creator>steve</dc:creator>
				<category><![CDATA[BSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[code]]></category>

		<guid isPermaLink="false">http://sickbiscuit.com/blog/2007/04/03/php-predefined-variables-on-bsd/</guid>
		<description><![CDATA[I&#8217;ve been getting ready for the deployment of wow4kids.com and one of the final features to be into place was restricting access to the administrative back-end.
I enabled admin routing in CakePHP and put all the back-end code into admin_* functions in my controller which are accessible via /admin/controller/action. I wanted to enable some form of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting ready for the deployment of <a href="http://wow4kids.com/">wow4kids.com</a> and one of the final features to be into place was restricting access to the administrative back-end.</p>
<p>I enabled <a href="http://blog.evansagge.com/2006/11/06/configure-cake_admin-routes-in-cakephp/">admin routing</a> in <a href="http://cakephp.org/">CakePHP </a>and put all the back-end code into <code>admin_*</code> functions in my controller which are accessible via /admin/<em>controller</em>/<em>action</em>. I wanted to enable some form of access control but without utilising a full user management system which would have been overkill.</p>
<p>The <code>/admin/</code> directory only exists through some <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html">mod_rewrite</a> magic so I couldn&#8217;t just use a simple <code>.htaccess</code> file. After much head-scratching and reading of documentation I arrived at a simple solution:</p>
<ol>
<li> I created a <code>.htaccess</code> protected directory, <code>/adminauth/</code></li>
<li> in this directory I created an <code>index.php</code> file which redirected to a URL passed to it via HTTP GET</li>
<li> in <code>/app/app_controller.php</code> I  defined a <code>beforeFilter()</code> function which uses a regular expression to determine if the called action contained â€œadmin_â€ in its name</li>
<li>if so, check if the <code>$_SERVER['AUTH_TYPE']</code> variable is set</li>
<li>redirect to <code>/adminauth/</code>, passing the current URL, if it isn&#8217;t set</li>
<li>let <a href="http://httpd.apache.org/docs/1.3/mod/mod_auth.html">mod_auth</a> take care of the rest</li>
</ol>
<p>This worked a charm on my home Linux box, but when it came to testing the code on the iMac the site is being developed on, the script couldn&#8217;t detect the <a href="http://uk2.php.net/manual/en/reserved.variables.php">server variable</a> and was thrown into an infinite loop of redirects, doh!</p>
<p>The same result was had when I uploaded the code to the <a href="http://pair.com/">FreeBSD web-host</a> the site will be deployed to, so I had no choice but to rethink my solution.</p>
<p>It was either going to be sessions or cookies and in the moment cookies seemed appealing. I changed the controller to check <code>$_COOKIE[]</code> instead of <code>$_SERVER[]</code> and <code>/adminauth/index.php</code> to call <code>setcookie()</code> . It seems to be working so far, fingers crossed it&#8217;ll be suitable for production purposes!</p>
]]></content:encoded>
			<wfw:commentRss>http://sickbiscuit.com/blog/2007/04/03/php-predefined-variables-on-bsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

