<?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>Intrepid Blog &#187; parse</title>
	<atom:link href="http://blog.affien.com/archives/tag/parse/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.affien.com</link>
	<description>A few thoughts</description>
	<lastBuildDate>Mon, 01 Mar 2010 00:58:01 +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>Parsing $_SERVER[&#039;PATH_INFO&#039;]</title>
		<link>http://blog.affien.com/archives/2004/12/12/parsing-_serverpath_info/</link>
		<comments>http://blog.affien.com/archives/2004/12/12/parsing-_serverpath_info/#comments</comments>
		<pubDate>Sun, 12 Dec 2004 11:20:34 +0000</pubDate>
		<dc:creator>Bas Westerbaan</dc:creator>
				<category><![CDATA[Code sniplets]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[path_info]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.w-nz.com/archives/2004/12/12/parsing-_serverpath_info/</guid>
		<description><![CDATA[The PHP global variable $_SERVER['PATH_INFO'] contains the path suffixed to a PHP script, if I would call the URL:
http://domain.ext/path/to/script.php/foo/bar.htm?a=b&#038;c=d
Then $_SERVER['PATH_INFO'] would contain:
/foo/bar.htm
Traditionaly the $_GET variables are used for certain parameters like a page to display:
http://domain.ext/page.php?page=about.htm
This method is easy to program, but not only looks strange, but also is very search engine unfriendly. Most searchengines ignore [...]]]></description>
			<content:encoded><![CDATA[<p>The PHP global variable <code>$_SERVER['PATH_INFO']</code> contains the path suffixed to a PHP script, if I would call the URL:</p>
<p><code>http://domain.ext/path/to/script.php/foo/bar.htm?a=b&#038;c=d</code></p>
<p>Then <code>$_SERVER['PATH_INFO']</code> would contain:</p>
<p><code>/foo/bar.htm</code></p>
<p>Traditionaly the <code>$_GET</code> variables are used for certain parameters like a page to display:</p>
<p><code>http://domain.ext/page.php?page=about.htm</code></p>
<p>This method is easy to program, but not only looks strange, but also is very search engine unfriendly. Most searchengines ignore the QueryString (the part of the URL after the <code>?</code>). And therefor would index the first <code>page.php?page=x</code> they would find and ignore the rest.<br />
Some searchengines like <a href="http://www.google.com">Google</a> do not ignore the query string, but would give a page without using a querystring for different content a way higher ranking.</p>
<p>Parsing the <code>$_SERVER['PATH_INFO']</code> is relatively easy, this code would do most of the stuff just fine:</p>
<blockquote><pre>if (!isset($_SERVER['PATH_INFO'])){
	$pathbits= array('');
}else{
	$pathbits = explode("/",  $_SERVER['PATH_INFO']);
}</pre>
</blockquote>
<p>The <code>$pathbits</code> array would always contain <code>/</code> as first element if a path info was provided, otherwise it will be an empty array.</p>
<p>Here is a quite simple example which parses the path info to decide which file to include:</p>
<blockquote><pre>&lt;?php
if (!isset($_SERVER['PATH_INFO'])){
	$pathbits= array('');
}else{
	$pathbits = explode("/",  $_SERVER['PATH_INFO']);
}
if (!isset($pathbits[1]) || $pathbits[1] == ""){
	$page = "default"
}else{
	$page = basename($pathbits[1]);
}
$file = "./pages/{$page}.php";
if (!is_file($file)){
	echo "File not found";
}else{
	require $file;
}
?&gt;</pre>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.affien.com/archives/2004/12/12/parsing-_serverpath_info/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
