<?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>irama.org &#187; Identifiers</title> <atom:link href="http://irama.org/news/category/technology/web/identifiers/feed/" rel="self" type="application/rss+xml" /><link>http://irama.org</link> <description>the web and I</description> <lastBuildDate>Tue, 08 Nov 2011 11:00:36 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Test support for short URL auto-discovery</title><link>http://irama.org/news/2010/07/06/test-support-for-short-url-auto-discovery/</link> <comments>http://irama.org/news/2010/07/06/test-support-for-short-url-auto-discovery/#comments</comments> <pubDate>Tue, 06 Jul 2010 09:29:10 +0000</pubDate> <dc:creator>Andrew Ramsden</dc:creator> <category><![CDATA[Identifiers]]></category> <category><![CDATA[Web]]></category> <guid
isPermaLink="false">http://irama.org/?p=673</guid> <description><![CDATA[Short URL autodiscovery sounds like a good idea to me. The easiest way for a developer to integrate this mechanism is to use the link element in your document&#8217;s &#60;head>, e.g: &#60;link rel="shorturl" href="http://irama.org/673" /> Or if you are using WordPress there are few handy plugins that do this automatically (for example: Short link maker [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://sites.google.com/a/snaplog.com/wiki/short_url">Short URL autodiscovery</a> sounds like a good idea to me. The easiest way for a developer to integrate this mechanism is to use the link element in your document&#8217;s <code
class="xhtml">&lt;head></code>, e.g:</p><pre><code class="xhtml">&lt;link rel="shorturl" href="http://irama.org/673" /></code></pre><p>Or if you are using WordPress there are few handy plugins that do this automatically (for example: <a
href="http://wordpress.org/extend/plugins/short-link-maker/">Short link maker</a> and <a
href="http://wordpress.org/extend/plugins/shorter-links/">Shorter links</a>).</p><h2>So what?</h2><p>But who&#8217;s going to know you&#8217;ve gone to all this trouble? How far has support for auto-discovery penetrated? I think it would be great if social media client applications would offer my short URL to users when they choose to shorten URLs within their posts, but I can&#8217;t find much documentation about which if any apps will pick up and use short URLs exposed in this way.</p><h2>Go forth and test</h2><p>This post can serve as a test, and a collection point for data, leave a comment if you have tested a new client application (include the version if known), and I&#8217;ll do the same.</p> ]]></content:encoded> <wfw:commentRss>http://irama.org/news/2010/07/06/test-support-for-short-url-auto-discovery/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Slightly nicer URLs</title><link>http://irama.org/news/2009/10/17/slightly-nicer-urls/</link> <comments>http://irama.org/news/2009/10/17/slightly-nicer-urls/#comments</comments> <pubDate>Sat, 17 Oct 2009 05:32:23 +0000</pubDate> <dc:creator>Andrew Ramsden</dc:creator> <category><![CDATA[Identifiers]]></category> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://irama.org/?p=328</guid> <description><![CDATA[As we know, all unique online resources should be addressable with a unique URL. However, not all URLs were created equal. Some URLs are &#8220;nicer&#8221; than others. For example, URLs with query string parameters are often considered to belong to the &#8220;not so nice&#8221; URL category: http://example.com/?p=1234&#038;vH=10&#038;Session_ID=er5DKJn838JK2dfs In general, what I consider to be &#8220;nice&#8221; [...]]]></description> <content:encoded><![CDATA[<p>As we know, all unique online resources should be addressable with a unique URL.</p><p>However, not all URLs were created equal. Some URLs are &#8220;nicer&#8221; than others. For example, URLs with query string parameters are often considered to belong to the &#8220;not so nice&#8221; URL category: <samp>http://example.com/?p=1234&#038;vH=10&#038;Session_ID=er5DKJn838JK2dfs</samp></p><p>In general, what I consider to be &#8220;nice&#8221; or &#8220;not so nice&#8221; URLs is a lengthy topic, and I&#8217;ll only touch on part of it today. Suffice to say, that for some purposes, I believe using query string parameters is not the worst crime you can commit. In fact, in some cases, I believe they are perfectly acceptable.</p><p>Take the following URL for instance: <samp>http://example.com/books/?format=html&#038;order=alphabetical&#038;page=2</samp>. Although query string parameters mean this URL is a little tricky to read, at least it uses human-readable parameter keys and values. And because slashes <samp>/</samp> in URLs imply heirarchy, the only good alternative for this type of URL would be a <a
href="http://www.w3.org/DesignIssues/MatrixURIs.html">Matrix URL</a>, like this: <samp>http://example.com/books/;format=html;order=alphabetical;page=2</samp>.</p><p>Implementing Matrix URLs within web applications can be difficult, requiring extra server-side redirects or client-side trickery because by default, a HTML form won&#8217;t submit data formatted as a Matrix URL.</p><p>That&#8217;s why I believe query strings aren&#8217;t so bad, sometimes they really come in handy.</p><h2>Repeated parameters</h2><p>That said, when using checkboxes (or heaven-forbid) multi-select controls to submit data using the GET method, some server-side languages (like PHP) require that you add <code
class="xhtml">[]</code> to the end of the name attribute of each control, for example: <code
class="xhtml">&lt;input type="checkbox" name="items[]" value="item1" />&lt;input type="checkbox" name="items[]" value="item2" /></code></p><p>For my money, this results in &#8220;not so nice&#8221; URLs, for example: <samp>http://example.com/books/?items[]=item1&#038;items[]=item2</samp></p><p>I know it&#8217;s a subtle difference, but I much prefer: <samp>http://example.com/books/?items=item1&#038;items=item2</samp></p><p>The other benefit is that your HTML wouldn&#8217;t need to contain the <code
class="xhtml">[]</code> either: <code
class="xhtml">&lt;input type="checkbox" name="items" value="item1" />&lt;input type="checkbox" name="items" value="item2" /></code></p><h2>A problem</h2><p>The problem is, by default, if <code
class="xhtml">[]</code> doesn&#8217;t appear in your URLs, only the last &#8216;items&#8217; parameter will be accessible to PHP in the <code
class="php">$_GET</code> array.</p><h2>A solution</h2><p> I spent some time thinking about this, and decided the best thing to do would be to parse the URL myself.</p><pre><code class="php">/**
 * Returns query string parameters more intelligently from the URL than by using the $_GET array.
 *
 * When multiple parameters are encountered with the same name, they are stacked into an
 * array. This means all URL data can be accessed without using brackets in name attributes
 * For example, typically you would use: &lt;input name="items[]" /> resulting in &#038;items[]=id1&#038;items[]=id2
 * However, using this method you can use: &lt;input name="items" /> resulting in &#038;items=id1&#038;items=id2
 *
 * @author Andrew Ramsden
 * @see: http://irama.org/news/2009/10/17/slightly-nicer-urls/
 * @license GNU GENERAL PUBLIC LICENSE (GPL) &lt;http://www.gnu.org/licenses/gpl.html>
 *
 * @param String $url (optional) A URL to parse for query string variables. If not set, the
 *        current requested URI will be parsed.
 * @return Array An associative array with all query string variables. Multiple parameters
 *         are stacked into a nested array.
 */
function getURLVariables ($url='') {
	$url = !empty($url) ? parse_url($url) : parse_url($_SERVER['REQUEST_URI']);
	$result = array();
	$queryStrParams = explode('&#038;',$url['query']);
	foreach ($queryStrParams as $param) {
		$paramKeyVals = explode('=',$param, 2);
		if (!isset($paramKeyVals[0])) continue;
		$key = $paramKeyVals[0];
		$val = isset($paramKeyVals[1])?$paramKeyVals[1]:'';
		if (substr($key,-6) == '%5B%5D') { // support ugly urls too
			$result[substr($key,0,-6)][] = $val;
		} else if (!isset($result[$key])) { // add new param to the results array
			$result[$key] = $val;
		} else { // this param already exists, stack into an array
				if (is_array($result[$key])) {
					$result[$key][] = $val; // add to existing array
				} else {
					$result[$key] = array($result[$key], $val); // create new array
				}
		}
	}
	return $result;
}</code></pre><p>Now instead of using: <code
class="php">$items = $_GET['items'];</code> you can use <code
class="php">$items = getURLVariables()['items'];</code> and access all the data from your <em>slightly nicer URLs</em>.</p><p>Feedback appreciated, let me know what you think.</p> ]]></content:encoded> <wfw:commentRss>http://irama.org/news/2009/10/17/slightly-nicer-urls/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
