<?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>Verbophobia &#187; PHP</title>
	<atom:link href="http://www.blyon.com/blog/index.php/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blyon.com/blog</link>
	<description>Tech and other thoughts of Barrett Lyon</description>
	<lastBuildDate>Mon, 30 Aug 2010 23:48:09 +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>Build your own URL shortener</title>
		<link>http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/</link>
		<comments>http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 23:48:09 +0000</pubDate>
		<dc:creator>Barrett Lyon</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Twitter Research]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[TinyURL]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[URL Shortener]]></category>

		<guid isPermaLink="false">http://www.blyon.com/blog/?p=1195</guid>
		<description><![CDATA[Build your own URL shortener!  Quick and simple instructions and code to start your own URL shortener service.]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td><img src="http://r1.3crowd.com/blyon/blogimg/url_logos.jpg">
</td>
<td>There are a lot of URL shorteners out there such as <a href="http://bit.ly">bit.ly</a>, <a href="http://www.tinyurl.com">tinyurl.com</a>, <a href="http://is.gd">is.gd</a>, <a href="http://tiny.cc">tiny.cc</a>.  The list of services is large.  For those of you that don&#8217;t know what a URL shortener is, it&#8217;s a piece of software that converts very long URLs such as:</p>
<p>http://www.blyon.com/blog/index.php/2010/08/28/build-your-own-url-shortener</p>
<p>Into: http://blyon.com/?efa</p>
<p>  This make the URL easy to cut and paste and reduces the characters you use for things such as Twitter.
</td>
</tr>
</table>
<p>I&#8217;ve been using <a href="http://www.tinyurl.com">TinyURL.com</a> for ages.  This morning I wondered to myself, &#8220;why not just use blyon.com?&#8221;  After all, the domain is shorter than TinyURL by 3 characters and if it&#8217;s just me using <a href="http://blyon.com/t/">my service</a> the hash only needs to be about 3 characters long because I am not storing millions of URLs.  Other services use a long hash (7+ characters) because they need more unique ways to identify URLs.</p>
<p>It took all of 30 minutes to write the code, and maybe another 30 to debug it.  </p>
<h3>Here&#8217;s how it works and how to setup your own!</h3>
<p>Go to <a href="http://www.blyon.com/t/">http://www.blyon.com/t</a> to input the URL and get the short URL which uses http://blyon.com/? as the base.  There&#8217;s a simple PHP script inside /t/ which creates the hash and puts it into a two table MySQL database.  I used /t/ just because I already had something at the root of blyon.com.  </p>
<p>I added another snippet of code on blyon.com&#8217;s index.php page which figures out if someone is trying to lookup a hash or not.  If it finds a hash that&#8217;s valid, it does a 302 redirect to the right location.  The 302 redirect is an easy location director built right into HTTP, so basically you&#8217;re telling a browser that goes to the short URL to go somewhere else.</p>
<table>
<tr>
<td>
Now, why do this?  For starters I was trying to wake up and wanted to have something to do while drinking coffee (the NPR stream was down).  However, there may be a lot of SEO reasons to do this.  For one, all my links I post are linked back to blyon.com, which means if something I tweet goes around the block a few times, it will all point back at blyon.com.   Taking this one step further might mean that I should also allow for special keywords to be created, thus helping google learn indexicals that I want valued for my web site.  The third great reason to do this (besides keeping oneself busy while drinking coffee) is to maintain your own links.  If TinyURL goes down someday, everything you have ever linked to will stop working as well.  However, who&#8217;s to say your (or my) admin skills are better than theirs.
</td>
<td><img width=250 src="http://r1.3crowd.com/blyon/blogimg/bsdcup2.jpg"></td>
</tr>
</table>
<p>Anyway, here&#8217;s the code!</p>
<p>The entire package as a tar:  <a href="http://blyon.com/t/redir.tar.gz">redir.tar.gz</a></p>
<p>To create the TinyURL you need this PHP code (my /t/ index page):  index.php</p>
<p>The database include code: dbconfig.php</p>
<p>To figure out if a request is for your main index page or a shortened URL: mainindex.php </p>
<p>The MySQL database you&#8217;ll need:  redir.mysql</p>
<p>PS:  Thanks to Nathan Hickson for helping me debug this.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/&amp;title=Build+your+own+URL+shortener+'></a></div><div class='dd_button'><script type='text/javascript'>reddit_url = http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/;reddit_title = Build+your+own+URL+shortener+;reddit_newwindow='1';</script><script type='text/javascript' src='http://www.reddit.com/static/button/button2.js'></script></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/" data-count="vertical" data-text="Build your own URL shortener " data-via="" >Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2.2.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://www.blyon.com/blog/index.php/2010/08/30/build-your-own-url-shortener/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Export your Tweets with PHP</title>
		<link>http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/</link>
		<comments>http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 18:49:14 +0000</pubDate>
		<dc:creator>Barrett Lyon</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tweets]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.blyon.com/blog/?p=45</guid>
		<description><![CDATA[Exporting your Tweets via PHP should be simple, but there are several overly complicated tools that exist which are just annoying.  Here's a script to make that easy.]]></description>
			<content:encoded><![CDATA[<p>Exporting your Tweets via PHP should be simple.  There are several tools that exist but they are annoying and overly complicated.  If you want to print your last 20 Tweets on your web page (like I did with the front page of <a href="http://blyon.com">blyon.com</a>), you can now use my simple script.</p>
<p>The first hack at it failed quickly because Twitter actually rate limits how many times a single host can pull the XML data per-hour.  To fix the rate limit issue I added a very basic cache function to the script which limits the requests to 60 an hour.</p>
<p>Setup and usage is simple, you include the PHP as you always would:</p>
<pre>include("./twitter-1.0.php");</pre>
<p>Configure the script by editing these items:</p>
<pre>
/* define where to store the cached result */
$CACHEDIR="/tmp/";

/* define your username */
$USERNAME="BarrettLyon";

/* define the max number of tweets to output */
$MAXTWEETS=20;

/* error message when twitter fails */
$ERRORMSG="Awh... Twitter is broken/down/not working/unhappy...";
</pre>
<p><P><br />
Then call twitterPrint() or just hack the script up to do what you want.</p>
<p>If you make changes or have improvement ideas, just comment on this posting and I will update the code.</p>
<p>Get the code here:   <a href="/twitter-1.1.php.txt">twitter-1.1.php</a>.</p>
<h3>UPDATE: I fixed a bunch of bugs, as a result I released v1.1.</h3>
<table border=1 style="display:none">
<tr>
<td>
<p>Barrett Lyon creates fun companies that do all sorts of innovative exciting things with video and security.</p>
<p>CDN <a href="http://www.blyon.com/cdn.php">cdn</a><br />
<a href="http://www.blyon.com.com">BitGravity</a>BitGravity Barrett Lyon<br />
<a href="http://www.blyon.com.com">BitGravity</a>BitGravity<br />
<a href="http://www.bitgravity.com">Barrett Lyon</a><br />
<a href="http://www.blyon.com/">LimeLight Networks</a> LimeLight Networks<br />
<a href="http://www.blyon.com/">EdgeCast</a> EdgeCast<br />
<a href="http://www.blyon.com/">CDNetworks</a> CDNetworks<br />
<a href="http://www.blyon.com/consulting.php">Consulting</a> Consulting<br />
<a href="http://www.blyon.com/speaker.php">Speaker</a> Speaking Opportunity<br />
<a href="http://www.blyon.com/speaking.php">Speaker</a> Speaking Opportunity<br />
<a href="http://www.blyon.com/content-delivery.php">Content Delivery Network</a> Content Delivery Network<br />
<a href="http://www.blyon.com/content-delivery.php">Content Delivery</a> Content Delivery<br />
<a href="http://www.blyon.com/flash-streaming.php">Flash Streaming</a> Flash Streaming<br />
<a href="http://www.blyon.com/interactive-video.php">Interactive Video</a> Interactive Video<br />
<a href="http://www.blyon.com/live-streaming.php">Live Streaming</a> Live Streaming<br />
<a href="http://www.blyon.com/live-video.php">Live Video</a> Live Video<br />
<a href="http://www.blyon.com/streaming-audio.php">Streaming Audio</a> Streaming Audio<br />
<a href="http://www.blyon.com/streaming-media.php">Streaming Media</a> Streaming Media<br />
<a href="http://www.blyon.com/video-delivery.php">Video Delivery</a> Video Delivery<br />
<a herf="http://www.blyon.com/video-hosting-service.php">Video Hosting Service</a> Video Hosting<br />
<a href="http://www.blyon.com/video-podcasting.php">Video Podcasting</a> Video Podcasting<br />
<a href="http://www.blyon.com/video-podcasts.php">Video Podcasts</a> Video Podcasts<br />
<a href="http://www.blyon.com/video-services.php">Video Services</a> Video Services<br />
<a href="http://www.blyon.com/video-streaming.php">Video Streaming</a> Video Streaming<br />
<a href="http://www.bitgravity.com/">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/content-delivery.html">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/flash-streaming.html">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/interactive-video.html">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/live-streaming.html">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/live-video.html">Barrett Lyon</a> Barrett Lyon<br />
<a href="http://www.bitgravity.com/streaming-media.html">Barrett Lyon</a> Barrett Lyon</p>
</td>
</tr>
</table>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/&amp;title=Export+your+Tweets+with+PHP'></a></div><div class='dd_button'><script type='text/javascript'>reddit_url = http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/;reddit_title = Export+your+Tweets+with+PHP;reddit_newwindow='1';</script><script type='text/javascript' src='http://www.reddit.com/static/button/button2.js'></script></div><div class='dd_button'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/" data-count="vertical" data-text="Export your Tweets with PHP" data-via="" >Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2.2.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://www.blyon.com/blog/index.php/2009/06/30/export-your-tweets-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
