<?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>Sean-O.com &#187; twitter</title>
	<atom:link href="http://www.sean-o.com/blog/index.php/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sean-o.com/blog</link>
	<description>Digital Craftsman &#38; Curator</description>
	<lastBuildDate>Thu, 26 May 2011 17:30:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tutorial: How To Create Your Own URL Shortener</title>
		<link>http://www.sean-o.com/blog/index.php/2009/08/11/tutorial-how-to-create-your-own-url-shortener/</link>
		<comments>http://www.sean-o.com/blog/index.php/2009/08/11/tutorial-how-to-create-your-own-url-shortener/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 19:15:15 +0000</pubDate>
		<dc:creator>seano</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[short URL]]></category>
		<category><![CDATA[shortener]]></category>
		<category><![CDATA[shortURL]]></category>
		<category><![CDATA[tr.im]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://www.sean-o.com/blog/?p=951</guid>
		<description><![CDATA[I&#8217;ve been thinking about posting this for a while now. Then came the announcement on Sunday, from URL shortening service tr.im, that they are shutting down, effective immediately. It brought to light the issues with relying on the cloud. Admittedly, this is not as devastating an announcement as your trusted e-mail, or even photo hosting, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about posting this for a while now. Then came the announcement on Sunday, from URL shortening service <strong>tr.im</strong>, that <a title="Tr.im URL Shortening Service Announces Shutdown" href="http://blog.tr.im/" target="_blank">they are shutting down</a>, effective immediately. It brought to light the issues with relying on the cloud.</p>
<p>Admittedly, this is not as devastating an announcement as your trusted e-mail, or even photo hosting, service going under. However, social media sites &#8212; primarily Twitter &#8212; have made URL shorteners almost a necessity, and some users have developed quite a bit of &#8220;social capital&#8221; in the form of links built and shared using a particular service.</p>
<p>Although tr.im promises to keep existing links active through the end of the year, there is currently no way to create new short URLs, nor is there any way to view information or statistics on any existing tr.im links. Poof, they&#8217;re gone. No warning, no recourse.</p>
<p><strong>UPDATE</strong>: Tr.im has restored their service. However, this unpredictability only reinforces the call to control your site and your brand.</p>
<p>Okay, so what can you do about it?<br />
<strong><em>Make your own URL shortener.</em></strong></p>
<p>As you&#8217;ll soon see, it&#8217;s easy, it&#8217;s fun, and puts the <strong>you</strong> in short URLs.</p>
<h3>Requirements</h3>
<ul>
<li>Web Server &#8212; preferably one you host yourself, with control over basic site settings</li>
<li>Web Development Language &#8212; using PHP here, but this code can be adapted to ASP.NET, ColdFusion, etc.</li>
<li>Database &#8212; MySQL featured, but SQL Server, PostgreSQL, etc. would work</li>
<li>Ideally, you&#8217;ll want a short domain to set this up on.<br />www.joesautoglassandspareparts.com kinda defeats the purpose ;)</li>
</ul>
<h3>Examples</h3>
<p>Each of the following are short URLs to content on other sites:<br />
<a href="http://sean-o.com/babysafe" target="_blank">http://sean-o.com/babysafe</a><br/><br />
<a href="http://sean-o.com/getwindows7" target="_blank">http://sean-o.com/getwindows7 </a><br/><br />
<a href="http://sean-o.com/playtime" target="_blank">http://sean-o.com/playtime</a><br/></p>
<h3>Getting Started</h3>
<p>As mentioned above, we&#8217;ll be using PHP 5.2.x &amp; MySQL 4/5 for this tutorial &#8212; as these open-source technologies should be available to most of you. </p>
<p>The first thing you&#8217;ll need is a source for your short URLs. Easiest way to do that is with a MySQL database (or new table on your existing site&#8217;s database). Here&#8217;s the structure I used:</p>
<div class="wp-caption alignnone" style="width: 519px"><img title="Sean O's Short URL Tutorial: Table Structure" src="http://sean-o.com/images/shorturl_table.gif" alt="Sean O's Short URL Tutorial: Table Structure" width="509" height="158" /><p class="wp-caption-text">Sean O's Short URL Tutorial: Table Structure</p></div>
<p>You only really need the first three columns, the rest are for statistics &amp; future use (userID). Add/remove fields as you see fit &#8212; perhaps you may want a field for notes?</p>
<h3>The Script</h3>
<p>We&#8217;ll only need one script to accomplish the short URL resolution. Create a file called <em>shortURL.php</em> at the root of your site. (or you may choose a custom name &#038; path)</p>
<p>To begin, the first thing to do is grab the short URL &#8212; the segment after the base URL.<br />
e.g. http://sean-o.com/<strong>playtime</strong><br />
A little regex (regular expressions) goes a long way here to parse the short URL and strip extraneous characters.</p>
<pre lang="php">$expectedURL = trim($_SERVER['URL']);
$split = preg_split("{:80\/}",$expectedURL);
$shortURL = $split[1];
// security: strip all but alphanumerics &#038; dashes
$shortURL = preg_replace("/[^a-z0-9-]+/i", "", $shortURL);
</pre>
<p>Next, we&#8217;ll check this string to see if it matches a short URL in our database.</p>
<pre lang="php">$isShortURL = false;
$result = getLongURL($shortURL);
if ($result) { $isShortURL = true; }
$longURL = $result['longURL'];</pre>
<p>Finally, we check to see if our <em>$isShortURL</em> flag is set. If a matching short URL was found, we&#8217;ll redirect to it. If not, we&#8217;ll display our standard 404.</p>
<pre lang="php">if ($isShortURL)
{
	redirectTo($longURL, $shortURL);
} else {
	show404();  // no shortURL found, display standard 404 page
}</pre>
<h3>The Functions</h3>
<p>The primary function &#8212; get the long URL associated with the passed short URL, if it exists.</p>
<pre lang="php">function getLongURL($s)
{
	// define these variables for your system
	$host = ""; $user = ""; $pass = ""; $db = "";
	$mysqli = new mysqli($host, $user, $pass, $db);
	// you may just want to fall thru to 404 here if connection error
	if (mysqli_connect_errno()) { die("Unable to connect !"); }
	$query = "SELECT * FROM urls WHERE shorturl = '$s';";
	if ($result = $mysqli->query($query)) {
	    if ($result->num_rows > 0) {
		while($row = $result->fetch_assoc()) {
			return($row);
		}
	    } else {
	    	return false;
	    }
	} else {
		return false;
	}
	$mysqli->close();
}</pre>
<p>Perform the URL redirection.</p>
<pre lang="php">function redirectTo($longURL)
{
	// change this to your domain
	header("Referer: http://www.your-domain-here.com");
	// use a 301 redirect to your destination
	header("Location: $longURL", TRUE, 301);
	exit;
}</pre>
<p>Finally, display your standard 404 page here.</p>
<pre lang="php">function show404()
{
	// display/include your standard 404 page here
	echo "<html><head></head><body>404 Page Not Found.</body></html>";
	exit;
}</pre>
<h3>Wire It Up</h3>
<p>Okay, so we have the script&#8230; now what? Well, the &#8220;special sauce&#8221; here is the <strong>404 redirect</strong>. What we&#8217;re simply doing is replacing (or augmenting) your site&#8217;s 404 page with one that checks a database for a URL shortcut. If one is listed that matches, redirect to it. If not, display your standard (or <a href="http://www.instantshift.com/2009/03/24/creative-404-error-pages-around-for-inspiration/" target="_blank">not so standard</a>) 404 error message.</p>
<p>You&#8217;ll need to modify your site&#8217;s existing 404 error page, or (recommended) create a new one. If creating a new one, make sure your site is set to point to this file. For IIS (5/6): Go to your web site, <em>Properties, Custom Errors, 404, Edit Properties&#8230;</em> For Apache, edit your .htaccess file thusly: <em>ErrorDocument 404 /shortURL.php</em>. (replace with your custom path as appropriate)</p>
<h3>Now, Run With It (Additional, Optional Steps)</h3>
<p>If you&#8217;ll be using this with any regularity, you&#8217;ll probably want to create an admin panel page to quickly add &amp; manage your URLs (I&#8217;m simply using a MySQL GUI &#8212; the great <a title="HeidiSQL - MySQL GUI" href="http://www.heidisql.com" target="_blank">HeidiSQL</a>). Consider whether you want to use custom short URL names, or just generate a random 4-5 character string (or both!). If you&#8217;re a statistics nut, you might want to capture more than just the user&#8217;s IP and/or build a stats page.</p>
<p>If you&#8217;re looking to &#8220;monetize&#8221; (ahem, see above), you may want to frame the linked site under a toolbar with your site&#8217;s branding, a la the &#8220;Digg Bar&#8221;. I highly recommend against this, however, as many users consider this practice an annoyance.</p>
<p>If your domain name is longer than, say, 8 characters, consider purchasing a second domain for exclusive short URL serving. Two-letter country-based domains such as .ly and .to are popular. Flickr&#8217;s recent purchase of http://flic.kr was especially clever.</p>
<h3>Conclusion</h3>
<p>So there you have it. Your very own, shiny new, URL shortening service&#8230; in <strong>under 50 lines</strong> of code!</p>
<p>Be sure to test. I suggest trying the following: a short URL you&#8217;ve created, a known working URL on your site (make sure you didn&#8217;t break anything!), and a known incorrect URL (test the standard 404). Also, be mindful of the security implications. Make sure following best practices with regards to MySQL security, and be sure to sanitize all URLs. Ensure your server is running the latest versions of software with the latest patches.</p>
<p><strong>Disclaimer</strong>: This article is just to get you started. The code presented here is most certainly &#8220;quick &amp; dirty&#8221;, and can surely be optimized. This code may or may not work for you, and I cannot be held responsible for any damage that may occur to your site as a result of implementing this.</p>
<p>If you end up implementing this on your site, I&#8217;d love to see it. Post an example here in the comments, or <strong><a href="http://twitter.com/seanodotcom" target="_blank">follow me on twitter</a></strong> and hit up @seanodotcom. If you&#8217;ve ported this code to other languages/databases, drop me a line.</p>
<p>Thanks for reading,<br />
<strong><em>SEAN O</em></strong><br />
<a href="http://twitter.com/seanodotcom"><img title="Follow Sean O (@seanodotcom) on Twitter" src="http://sean-o.com/images/icons/twitter/twitter-03.png" alt="Follow Sean O (@seanodotcom) on Twitter" width="80" height="15" /></a><br />
<br clear='all' /></p>
<h3>Advantages</h3>
<ul>
<li>You&#8217;re in complete control</li>
<li>You can specify random short URLs or custom ones, using related keyword(s)</li>
<li>You can collect virtually any statistics you wish</li>
<li>Excellent for site branding &#8212; your URL appears on every link!</li>
</ul>
<h3>Disadvantages</h3>
<ul>
<li>You&#8217;re responsible for maintaining uptime &#8212; as your site goes, so goes the service</li>
<li>You need to build any related services &#8212; stats tracking, APIs, user registration, etc.</li>
<li>Your site&#8217;s subdirectory names will override custom short URLs of the same name</li>
<li>Every 404 on your site will incur a database hit &#8212; be sure to keep your main site links fresh (<i>Thanks 5Min</i>)
<li>Utility varies inversely with the length of the primary domain name</li>
</ul>
<h3>Alternatives</h3>
<ul>
<li>Simply use another service &#8212; bit.ly, cli.gs, etc. (but that&#8217;s no fun, and you&#8217;re again vulnerable)</li>
<li>Creative use of <em>htaccess</em> or <em>IIS Rewrite</em></li>
</ul>
<p></p>
<p><em>p.s. the short URL for this post is <a href="http://sean-o.com/short-URL" target="_blank">http://sean-o.com/short-URL</a></p>
<p><a class="retweet" href="http://sean-o.com/short-URL" target="_blank">http://sean-o.com/short-URL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-o.com/blog/index.php/2009/08/11/tutorial-how-to-create-your-own-url-shortener/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Twitter Tracker</title>
		<link>http://www.sean-o.com/blog/index.php/2009/06/03/twitter-tracker/</link>
		<comments>http://www.sean-o.com/blog/index.php/2009/06/03/twitter-tracker/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 01:05:10 +0000</pubDate>
		<dc:creator>seano</dc:creator>
				<category><![CDATA[Celebrity]]></category>
		<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[Funny]]></category>
		<category><![CDATA[conan]]></category>
		<category><![CDATA[obrien]]></category>
		<category><![CDATA[tonight show]]></category>
		<category><![CDATA[tracker]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.sean-o.com/blog/?p=937</guid>
		<description><![CDATA[Funny not so much for its content, as its presentation.]]></description>
			<content:encoded><![CDATA[<p>Funny not so much for its content, as its presentation.<br />
<object width="384" height="283" data="http://widgets.nbc.com/o/4727a250e66f9723/4a271c1569e80eec/4a26865f9f898614/35378b95/-cpid/4c2e843981e0a43f" type="application/x-shockwave-flash"><param name="id" value="W4727a250e66f97234a271c1569e80eec" /><param name="wmode" value="transparent" /><param name="allowNetworking" value="all" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="src" value="http://widgets.nbc.com/o/4727a250e66f9723/4a271c1569e80eec/4a26865f9f898614/35378b95/-cpid/4c2e843981e0a43f" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-o.com/blog/index.php/2009/06/03/twitter-tracker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>He&#8217;s Just Not That Into Me</title>
		<link>http://www.sean-o.com/blog/index.php/2009/03/31/hes-just-not-that-into-me/</link>
		<comments>http://www.sean-o.com/blog/index.php/2009/03/31/hes-just-not-that-into-me/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 17:20:13 +0000</pubDate>
		<dc:creator>seano</dc:creator>
				<category><![CDATA[Celebrity]]></category>
		<category><![CDATA[Culture]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[friend]]></category>
		<category><![CDATA[friending]]></category>
		<category><![CDATA[rejection]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.sean-o.com/blog/?p=899</guid>
		<description><![CDATA[Well, this was a first. For the first time in over 20 years as a member of the digital universe (save for my foray into online dating): I&#8217;ve been rejected as a potential &#8220;friend&#8221; online. It was bound to happen, sure. But I didn&#8217;t expect it from someone I had actually met in real life. [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignnone" style="width: 506px"><img title="Facebook Rejection" src="/images/facebook_rejection.gif" alt="Rejected" width="496" height="169" /><p class="wp-caption-text">Rejected</p></div>
<p>Well, this was a first.</p>
<p>For the first time in over 20 years as a member of the digital universe (save for my foray into online dating):</p>
<h3>I&#8217;ve been rejected as a potential &#8220;friend&#8221; online.</h3>
<p>It was bound to happen, sure. But I didn&#8217;t expect it from someone <em>I had actually met in real life</em>. And had over for poker in my home.</p>
<p>Now, I completely understand his rationale. The person in question lives in the L.A. area and hangs in celebrity circles; He gets phone calls from <strong>Ben Stiller</strong>, and I&#8217;d seen photos of him at the house of the beautiful <strong><a title="Jenna Fischer" href="http://en.wikipedia.org/wiki/Jenna_Fischer" target="_blank">Jenna Fischer</a></strong> (born just one week after me, BTW). Also, he has close to 3,000 MySpace friends. So I imagine he wants to keep the fanbois on <strong>MySpace</strong>, and leave <strong>Facebook </strong>as a place for those he is closest with. Quite understandable.</p>
<p>This interesting response still came as a bit of a surprise. Which makes sense, because he is an interesting guy&#8230; <em>which</em>&#8230; is why I wanted to keep up with him in the first place! I throw up a little in my mouth when I think of joining MySpace, so that&#8217;s not happening. If only he were on <a title="Twitter - Sean O (seanodotcom)" href="http://twitter.com/seanodotcom" target="_blank"><strong>Twitter</strong></a>&#8230;</p>
<p>Well, in any event, no hard feelings, Joe. Good luck in your travels. And say hi to Jenna for me. Big fan.</p>
<p>(hmm, is <em>she</em> on Facebook&#8230;?)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-o.com/blog/index.php/2009/03/31/hes-just-not-that-into-me/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Watch the Mars Phoenix Landing</title>
		<link>http://www.sean-o.com/blog/index.php/2008/06/02/watch-the-mars-phoenix-landing-on-mars/</link>
		<comments>http://www.sean-o.com/blog/index.php/2008/06/02/watch-the-mars-phoenix-landing-on-mars/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 12:49:44 +0000</pubDate>
		<dc:creator>seano</dc:creator>
				<category><![CDATA[Astronomy]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[lander]]></category>
		<category><![CDATA[landing]]></category>
		<category><![CDATA[Mars]]></category>
		<category><![CDATA[NASA]]></category>
		<category><![CDATA[Phoenix]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.sean-o.com/blog/index.php/2008/06/02/watch-the-mars-phoenix-landing-on-mars/</guid>
		<description><![CDATA[Well, an artist&#8217;s rendering of it anyway, as I&#8217;m not aware of a ground crew set up for filming. Watch the Phoenix arrive at Mars, deploy its braking parachute, jettison its heat shield, fire its thrusters, land, unfurl its solar panels, deploy its instruments, scoop up some of Mars, and begin its analysis. See more [...]]]></description>
			<content:encoded><![CDATA[<p>Well, an artist&#8217;s rendering of it anyway, as I&#8217;m not aware of a ground crew set up for filming.</p>
<p><strong><a href="http://apod.nasa.gov/apod/ap080525m.html" title="NASA - Phoenix lander arrives at Mars" target="_blank">Watch the Phoenix arrive at Mars</a></strong>, deploy its braking  <a href="http://youtube.com/watch?v=thyTzCU9c2U">parachute</a>,  jettison its <a href="http://apod.nasa.gov/apod/ap050209.html">heat shield</a>, fire its thrusters, land, unfurl its  <a href="http://www.howstuffworks.com/solar-cell.htm">solar panels</a>,  deploy its instruments, scoop up some of Mars, and begin its  <a href="http://phoenix.lpl.arizona.edu/science.php">analysis</a>.</p>
<p>See more images from the Phoenix at <a href="http://www.nasa.gov/phoenix/" title="Nasa - Phoenix Home Page" target="_blank">its web site</a>. You can even follow Phoenix updates as they occur on Twitter at <a href="http://twitter.com/MarsPhoenix" title="Twitter - NASA Phoenix" target="_blank"><span class="a">twitter.com/MarsPhoenix.</span></a></p>
<h5><font color="#993366">Thanks, Pop</font></h5>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-o.com/blog/index.php/2008/06/02/watch-the-mars-phoenix-landing-on-mars/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Twitter Explained</title>
		<link>http://www.sean-o.com/blog/index.php/2008/03/08/twitter-explained/</link>
		<comments>http://www.sean-o.com/blog/index.php/2008/03/08/twitter-explained/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 18:19:23 +0000</pubDate>
		<dc:creator>seano</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[explanation]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.sean-o.com/blog/index.php/2008/03/08/twitter-explained/</guid>
		<description><![CDATA[The folks over at Common Craft have put together another great instructional video on Twitter &#8212; what it is and why we use it. It explains everything about the orange box you see on the right. If you&#8217;re on twitter, shoot me an email and let me know!]]></description>
			<content:encoded><![CDATA[<p>The folks over at Common Craft have put together another great instructional video on <a href="http://www.twitter.com" title="Twitter" target="_blank">Twitter</a> &#8212; what it is and why we use it.   It explains everything about the orange box you see on the right.  If you&#8217;re on twitter, shoot me an email and let me know!</p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ddO9idmax0o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ddO9idmax0o" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-o.com/blog/index.php/2008/03/08/twitter-explained/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

