<?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>arkinEx Codex &#187; include</title>
	<atom:link href="http://www.arkinex.com/contains/include/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arkinex.com</link>
	<description>the place where all my code can be viewed</description>
	<lastBuildDate>Wed, 04 Nov 2009 20:39:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Advanced Navigation using Includes</title>
		<link>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/</link>
		<comments>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 07:33:05 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://arkinex.psycholz.com/2007/09/15/advanced-navigation-using-includes/</guid>
		<description><![CDATA[A very simple way of doing the index.php?page=page_here. Includes a few configuration options. Written in php4, works in php5, mostly so you can view the source and attempt at understanding how it works. /*--- Configuration ---*/ &#160; $page = Array&#40;&#41;; &#160; // Edit these vars or leave as is. &#160; $page&#91;'home'&#93; = &#34;home&#34;; &#160; // [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/resources/post-preview-thumbs/sml-070915-php-nav.jpg" alt="PHP Navigation tutorial" align="right" />A very simple way of doing the index.php?page=<strong>page_here</strong>. Includes a few configuration options.</p>
<p>Written in php4, works in php5, mostly so you can view the source and attempt at understanding how it works.</p>
<p><span id="more-4"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*--- Configuration ---*/</span>
&nbsp;
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Edit these vars or leave as is.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;home&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Replace this with the default or main page.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;404&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Replace this with the 404 page, can be 'home' also or even $page['home'].</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This will be the format of your page so ?page=bla will be bla.php.</span>
&nbsp;
<span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// The trigger used so ?page=bla.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*--- Do not edit below! ---*/</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">ctype_alpha</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$pg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'trig'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://php.net/ctype_alpha" title="PHP Function: ctype_alpha" target="_blank"> ctype_alpha</a>  is used to make sure the &#8220;page&#8221; passed by the user only contains characters A-Z for security (so people can&#8217;t include /etc/passwd for example).</p>
<p><a href="http://www.php.net/file_exists" title="PHP Function: file_exists" target="_blank">file_exists</a> is used to determine whether the page + extension actually exist and if they don&#8217;t, the error page is then thrown.</p>
<p>An idea, if you want a readable page name from $pg, you could try</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$page_name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pg</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$page</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'format'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you have any further questions, please do not hesitate to leave a comment,<br />
I will update this snippet when features are suggested or questions and comments made.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/tutorials/4/advanced-navigation-using-includes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
