<?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>firsttube.com &#187; PHP</title>
	<atom:link href="http://www.firsttube.com/category/technology/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.firsttube.com</link>
	<description>crunchy nuggets, served semi-daily</description>
	<lastBuildDate>Tue, 03 Jan 2012 00:14:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A Guide to Base Changing For Short URLs</title>
		<link>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/</link>
		<comments>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 19:09:56 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1670</guid>
		<description><![CDATA[Some time ago, I developed a VERY simple way to fake a bit.ly-style short URL. On any server that uses any form of an integer to identify an article (either in the database or the URL), on an Apache server &#8230; <a href="http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I developed a VERY simple way to fake a bit.ly-style short URL.  On any server that uses any form of an integer to identify an article (either in the database or the URL), on an Apache server that supports mod_rewrite, you edit your .htaccess file like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">RewriteEngine Off
<span style="color: #000000; font-weight: bold;">&lt;</span>ifmodule mod_rewrite.c<span style="color: #000000; font-weight: bold;">&gt;</span>
RewriteEngine On
RewriteBase <span style="color: #000000; font-weight: bold;">/</span>
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_FILENAME<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>-f
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_FILENAME<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>-d
RewriteCond <span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>REQUEST_URI<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">!</span>^index.php$
RewriteRule . index.php <span style="color: #7a0874; font-weight: bold;">&#91;</span>NC,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>ifmodule<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>This essentially tells your server to redirect anything that isn&#8217;t a file or directory to index.php.</p>
<p>Then index.php looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//this is where you either query your database for a slug or build the URL</span>
<span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://your-site-goes-here.com/path/to/article'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 301 Moved Permanently'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Link: &lt; '</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;; rel=shortlink&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://your-site-goes-here.com/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>How do you get your short links? That&#8217;s easy.  Just run this function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$shorturl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>However, this isn&#8217;t the most compact way to condense.  Obviously, this is base36, the highest PHP can go.  But what about uppercase letters? And other characters?</p>
<p>So I set out, for some reason, to build a better condenser.</p>
<p>This is the result of several hours of work, mostly wasted, on some intellectual pursuit that was more a case of simply not letting it defeat me.  A few notes: I&#8217;m quite confident that given enough time, and if I cared, I could make the code cleaner and more efficient in some places. I&#8217;m also aware that on 32 bit machines, it maxes out at the integer limit. I does support signed integers though, from min to max.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ft_str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'0123456789abcdefghijklmnopqrstuvqwxyzABCDEFGHIJKLMNOPQRSTUVQWXYZ'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># uncomment the next line if you prefer to use potentially non-URL-safe base96
</span><span style="color: #666666; font-style: italic;"># $ft_str .= '0123456789abcdefghijklmnopqrstuvqwxyzABCDEFGHIJKLMNOPQRSTUVQWXYZ_@$!#%^&amp;*()=+\|}{][,;:~'; }
</span>
<span style="color: #000088;">$powers</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>
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$p</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><span style="color: #000088;">$p</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$powers</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_unconvert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$powers</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strrev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$sp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$decimal</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$base</span><span style="color: #339933;">,</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #000088;">$sp</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">.</span><span style="color: #000088;">$decimal</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_converter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">;</span> <span style="color: #000088;">$int</span><span style="color: #339933;">=</span><span style="color: #990000;">abs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">,</span><span style="color: #000088;">$powers</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$base</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$q</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">krsort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$powers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$powers</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #339933;">&gt;=</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$timesinto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #339933;">/</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$digit</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$timesinto</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$int</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$int</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$int</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$k</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$digit</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$int</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$int</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$int</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$pfx</span><span style="color: #339933;">.</span><span style="color: #000088;">$digit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ft_convert_demo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$ft_str</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ftc</span> <span style="color: #339933;">=</span> ft_converter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;Converting &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$num</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; into base &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ft_str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ftc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;Unconverting &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ftc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; to base 10: &quot;</span><span style="color: #339933;">.</span>ft_unconvert<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> ft_convert_demo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'50687'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/a-guide-to-base-changing-for-short-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;ve Been Hacked! WP-Lytebox Sucks</title>
		<link>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/</link>
		<comments>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 21:36:16 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1600</guid>
		<description><![CDATA[This is the third time I&#8217;ve had to spent serious time &#8220;fixing&#8221; WordPress.  Say what you will about my old &#8220;Small Axe&#8221; or &#8220;Flip&#8221; solutions, but I never had a problem.  With WordPress, I have found regular issues. This time, &#8230; <a href="http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img style="width: 150px; height: 150px; padding: 5px; float: right;" src="http://firsttube.com/uploads/2010/04/wordpress-hack-150x150.jpg" alt="Hacking WordPress" />This is the third time I&#8217;ve had to spent serious time &#8220;fixing&#8221; WordPress.  Say what you will about my old &#8220;Small Axe&#8221; or &#8220;Flip&#8221; solutions, but I never had a problem.  With WordPress, I have found regular issues.</p>
<p>This time, I traced the problem back to wp-lytebox, and I&#8217;m ashamed to say I&#8217;ve had to fix the same problem before.  It all started when I couldn&#8217;t load the post page in the backend of <a href='http://firsttube.com'>firsttube.com</a>.  Digging in, I eventually found a file called sys.php in the root of the site, and it listed the contents of my site and had a form that allowed someone to add a page, chmod a page, or delete a page.  Killer!</p>
<p>I found that it was defaulting to <em>/path/to/WP/wp-includes/plugins/wp-lytebo</em>x, and sure enough, digging into that directory revealed several other fun scripts, all of which gave someone the ability to access all the files on my site.  Fun!</p>
<p>I found that I already had replaced this plugin before, so I decided to get rid of it altogether, this now proving it wasn&#8217;t a misconfiguration, but rather, <a href="http://www.f-secure.com/vulnerabilities/SA200902421">a problem with the wp-lytebox itself</a>.</p>
<p>In this process, however, I was unable to fix my issue.  Visiting <em>/wp-admin/post-new.php</em> still rendered only a page footer, and nothing more.</p>
<p>So I starting fooling around in my directories looking for files that had been modified more recently than when I did my 2.9.2 upgrade.  One of the files? My <em>.htaccess</em> file.</p>
<p>&#8220;<em>This be odd,</em>&#8221; I thought to myself, &#8220;<em>I&#8217;ve changed this not, methinks.</em>&#8221;</p>
<p>Sure enough, there was a rogue line within: RewriteCond ^/default/$ /wp-admin/includes Huh?</p>
<p>I dug into that folder, and the .htaccess file there was recent too? It&#8217;s contents? <em>DefaultIndex users.php</em></p>
<p>Of course, I immediately opened users.php and found, as you might have guessed, a bunch of Russian crap. Savvy WP hackers will know, it&#8217;s not a real file, there is no users.php in the real wp-admin/includes directory.</p>
<p>I also found a folder that had two large files, both named core.XXXX where XXXX was a 4 digit number, and a massive 40 MB error_log.  Yikes.</p>
<p>I thought I had everything cleaned out, and I truly believed that the way in was wp-lytebox.  Then <a href="http://wordpress.org/support/topic/379659">I found this</a>.  And sure enough, all of the listed files were compromised.  So I nuked all the files, and replaced them all.  D&#8217;oh!</p>
<p>So, if you&#8217;re arriving via Google or Bing or Yahoo!, do NOT use wp-lytebox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/ive-been-hacked-wp-lytebox-sucks/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Behind the Scenes at OSNews</title>
		<link>http://www.firsttube.com/read/behind-the-scenes-at-osnews/</link>
		<comments>http://www.firsttube.com/read/behind-the-scenes-at-osnews/#comments</comments>
		<pubDate>Mon, 04 May 2009 22:55:57 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[OSNews]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1279</guid>
		<description><![CDATA[I just started putting together a series of articles I will be publishing on OSNews.  I&#8217;ve only roughly sketched it out, but in short, it&#8217;s going to discuss how OSNews works, how the PHP is structured, why we made certain &#8230; <a href="http://www.firsttube.com/read/behind-the-scenes-at-osnews/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just started putting together a series of articles I will be publishing on OSNews.  I&#8217;ve only roughly sketched it out, but in short, it&#8217;s going to discuss how <a href='http://osnews.com'>OSNews</a> works, how the PHP is structured, why we made certain architectural decisions, why we don&#8217;t use tried-and-true CMSes like WordPress, Slash, or Joomla!, and how, during peak traffic times, we have survived 30,000 unique visitors per hour on a single server.  <a href='http://osnews.com'>OSNews</a> didn&#8217;t happen by mistake: over a series of months, arguably years, we took a constant read of performance, hits, server load, and usability with the mission to continually improve load time, performance, and <abbr title="user experience">UX</abbr>.  We&#8217;ve just recently begun testing some new data presentation methods that I intend to include in my little exposé.</p>
<p>If you&#8217;re interested in some revealing behind-the-scenes info, feel free to ask questions now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/behind-the-scenes-at-osnews/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Flip 3.0.1</title>
		<link>http://www.firsttube.com/read/flip-301/</link>
		<comments>http://www.firsttube.com/read/flip-301/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:52:05 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Flip]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1229</guid>
		<description><![CDATA[I never expected to release another version of my old weblog project Flip, but while searching my own name in a new search engine, I came upon several vulnerability reports for Flip 3.0. I&#8217;ve known about them for awhile now, &#8230; <a href="http://www.firsttube.com/read/flip-301/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I never expected to release another version of my old weblog project <a href="http://firsttube.com/tag/flip">Flip</a>, but while searching my own name in a new search engine, I came upon several vulnerability reports for Flip 3.0.  I&#8217;ve known about them for awhile now, but having dropped Flip in favor of another project (which I&#8217;ve since abandoned, for the most part, in favor of WordPress), it seemed pointless to bother.  However, since there is an active exploit, I thought I&#8217;d release an update and a patch.</p>
<p>I don&#8217;t believe anyone out there is still using Flip, but if there is, this is how to defeat the script: simple add this line at line 102 of account.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'em'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;][&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Fail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and this at line 162:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nem'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;][&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Fail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Alternatively, you can download the modified file <a href="http://releases.smallaxesolutions.com/account.phps">here</a> or <a href="http://releases.smallaxesolutions.com/flip-3.0.1.zip">download Flip 3.0.1 here</a>.</p>
<p>It may sound odd, but I would highly recommend that you do *not* use this code.  It&#8217;s now 7 years old and the web is a much different place.  The code here is really not suited for running a website today.  That said, it was odd to unzip and install it and see that it actually works.  The rendering of most of the &#8220;themes&#8221; is weird (Fudge works great), but otherwise, everything worked.</p>
<p>If you are still a Flip user, I recommend you update your account.php page immediately, and if you have the time and inclination, upgrade to 3.0.1.  The following files have some minor changes:</p>
<ul class="list">
<li>account.php</li>
<li>index.php</li>
<li>inc/config.php</li>
<li>README.html</li>
</ul>
<p>Once again, this code is aged not particularly well suited for today&#8217;s web.  If you want a simple weblog, I recommend <a href="http://wordpress.org">WordPress</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/flip-301/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting Your Latest Tweet in WordPress</title>
		<link>http://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/</link>
		<comments>http://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 16:48:31 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Social Networking]]></category>

		<guid isPermaLink="false">http://firsttube.com/?p=1118</guid>
		<description><![CDATA[Although I posted yesterday how to add your latest tweet to WordPress without a plugin, I made several changes to the script before I posted it to make it more &#8220;generic&#8221; and re-usable. Since I&#8217;ve changed it quite a bit, &#8230; <a href="http://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Although I posted yesterday how to add your latest tweet to WordPress without a plugin, I made several changes to the script before I posted it to make it more &#8220;generic&#8221; and re-usable. Since I&#8217;ve changed it quite a bit, I decided to repost it.  This new script also autolinks @usernames and <a href="http://www.google.com/search?q=twitter+hash+tags">#hash tags</a>.</p>
<p>Directions are this easy: set the path of $tw_File with a static, writable file.  Set $tw_userid to your Twitter user id.  Done. </p>
<p>Download <a href="http://firsttube.com/s/latest-tweet"><strong>firsttube.com &#8220;get latest tweet&#8221; php snippet</strong></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/posting-your-latest-tweet-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sorting a Multi-Dimensional Array with PHP</title>
		<link>http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/</link>
		<comments>http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 18:52:48 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=1044</guid>
		<description><![CDATA[Every so often I find myself with a multidimensional array that I want to sort by a value in a sub-array. I have an array that might look like this: //an array of some songs I like $songs = array&#40; &#8230; <a href="http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Every so often I find myself with a multidimensional array that I want to sort by a value in a sub-array.  I have an array that might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//an array of some songs I like</span>
<span style="color: #000088;">$songs</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Smashing Pumpkins'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Soma'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Decemberists'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'The Island'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'3'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artist'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Fleetwood Mac'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'songname'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Second-hand News'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The problem is thus: I&#8217;d like to echo out the songs I like in the format &#8220;<em>Songname</em> (<em>Artist</em>),&#8221; and I&#8217;d like to do it alphabetically by artist.  PHP provides many functions for sorting arrays, but none will work here.  <em>ksort()</em> will allow me to sort by key, but the keys in the <em>$songs</em> array are irrelevant.  <em>asort()</em> allows me to sort and preserves keys, but it will sort $songs by the value of each element, which is also useless, since the value of each is &#8220;array()&#8221;.  <em>usort()</em> is another possible candidate and can do multi-dimensional sorting, but it involves building a callback function and is often pretty long-winded.  Even the examples in the PHP docs references specific keys. </p>
<p>So I developed a quick function to sort by the value of a key in a sub-array.  Please note this version does a case-insensitive sort. See subval_sort() below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> subval_sort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$subkey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$b</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$subkey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use it on the above, I would simply type:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$songs</span> <span style="color: #339933;">=</span> subval_sort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$songs</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'artist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$songs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is what you should expect see:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>
<span style="color: #009900;">&#40;</span>
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Fleetwood Mac
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Second<span style="color: #339933;">-</span>hand News
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Decemberists
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Island
        <span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">Array</span>
        <span style="color: #009900;">&#40;</span>
            <span style="color: #009900;">&#91;</span>artist<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> The Smashing Pumpkins
            <span style="color: #009900;">&#91;</span>song<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> Cherub Rock
        <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>The songs, sorted by artist. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/feed/</wfw:commentRss>
		<slash:comments>77</slash:comments>
		</item>
		<item>
		<title>PHP Weirdness</title>
		<link>http://www.firsttube.com/read/php-weirdness/</link>
		<comments>http://www.firsttube.com/read/php-weirdness/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 19:46:03 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Yahoo!]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=660</guid>
		<description><![CDATA[Beware: this post is definitely not for the feint of heart. It includes a lot of code. You have been warned. I wrote an application some time ago for my company that looks up the longitude and latitude of an &#8230; <a href="http://www.firsttube.com/read/php-weirdness/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Beware: this post is definitely not for the feint of heart.  It includes a lot of code.  You have been warned.</p>
<p>I wrote an application some time ago for my company that looks up the longitude and latitude of an address for use in our geocoding initiative.  It relied on yahoo_geo(), <a href="http://toys.lerdorf.com/archives/2005/11.html">a function written by PHP creator Rasmus Lerdorf</a> and the Yahoo Maps API.  It was largely dependent on this function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;amp;location='</span>
		<span style="color: #339933;">.</span><span style="color: #990000;">rawurlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/tmp/yws_geo_'</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	request_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tmp</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">43200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">libxml_use_internal_errors</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>Result<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>children<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p>This function worked for over two years for us with no problems at all.  Then suddenly, in the last month, it started getting spotty.  I fixed things by commenting out the caching parts of the function and forcing each execution to run again.  Then I got errors about the libxml_use_internal_errors() function, so I commented that out.  But today, the function just flat out failed, every single time returning the same error: </p>
<p><strong>Warning: file_get_contents(http://XXXXXXXXXX/XXX) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/intranet/html/fetch.php on line X</strong></p>
<p>What the heck? This code is all over the web.  I&#8217;ve tried a million permutations of this function, including using fopen() and ob_get_contents(), and none have worked.  And most frustratingly, I could load the URL successfully in Lynx and eLinks, so the machine could quickly and easily fetch the URL.</p>
<p>So I ventured into a sandbox I&#8217;ve never really played before: <a href="http://us2.php.net/manual/en/ref.curl.php">cURL</a>.   cURL is an interesting animal.  But the interesting thing is, once I got it working, it worked faster than ever! So, without further ado, here is the new and improved yahoo_geo() function: </p>
<p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> yahoo_geo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://api.local.yahoo.com/MapsService/V1/geocode?appid=rlerdorf&amp;#038;location='</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$location</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$stream</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stream</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'precision'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span><span style="color: #000088;">$val</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</p>
<p><small><strong>Note:</strong> If you&#8217;re reproducing these functions elsewhere, be careful &#8211; WordPress may have converted the quotes into smart quotes that will need to be fixed before this script will run properly. </small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/php-weirdness/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OSNews vs. WordPress</title>
		<link>http://www.firsttube.com/read/osnews-vs-wordpress/</link>
		<comments>http://www.firsttube.com/read/osnews-vs-wordpress/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 00:35:20 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[OSNews]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://firsttubecom/?p=656</guid>
		<description><![CDATA[I&#8217;ve spent quite a bit of time, over the last 5 or 6 days, diving into WordPress and learning what makes it tick.  Parts of WordPress are really impressive &#8211; just flat out cool. The way some of it works &#8230; <a href="http://www.firsttube.com/read/osnews-vs-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent quite a bit of time, over the last 5 or 6 days, diving into WordPress and learning what makes it tick.  Parts of WordPress are <em>really</em> impressive &#8211; just flat out <em><strong>cool</strong></em>. The way some of it works is fairly complex and deciphering it sometimes means reading page after page after page to understand an entire routine.  But sometimes, when you finally see, end to end, how something in WordPress works &#8211;  I mean really see individual bits of the engine &#8211; you have to admit it teaches you a little about PHP.  WordPress, underneath it all, is a pretty big beast and its strength and ubiquitous presence comes largely, I think, from the fact that it can do virtually anything.  The really sweet plugin system, the ways hooks work, &#8220;The Loop,&#8221; the dynamic options panel &#8211; it&#8217;s all very educational.  </p>
<p>The interesting thing here is that I&#8217;ve browsed the source of <a href="http://slashcode.com">Slash</a>, <a href="http://scoop.kuro5hin.org">Scoop</a>, <a href="http://phpnuke.org">phpNuke</a>, and now <a href="http://wordpress.org">WordPress</a>, and all of them are <strong>definitively</strong> more complex and much heavier than the entire <a href='http://osnews.com'>OSNews</a> codebase. Now, before you jump all over me &#8211; firstly, Slash and Scoop are Perl, and I don&#8217;t really read Perl, so I can&#8217;t speak as an expert there.  Secondly, WordPress and Nuke both are very portable and dynamic, whereas <a href='http://osnews.com'>OSNews</a> has a narrow focus and, location-wise, is very static.  But that aside, <a href='http://osnews.com'>OSNews</a> has withstood simultaneous link bombs from <a href="http://slashdot.org">Slashdot</a> and <a href="http://digg.com">Digg</a>.  As amazing as WordPress is, it&#8217;s mostly amazing that it functions at all and loads in less than 2 minutes per page with as much going on as I can see behind the scenes.   That&#8217;s not a cut on WordPress, by the way.</p>
<p>In fact, if anything , what is really impressed upon me is how smooth and simple <a href='http://osnews.com'>OSNews</a> code is, if I may be so bold.  OSNews runs superfast due, in part, to lots of creative caching, some on-demand, some via cron.  But it also does so because of highly efficient queries that are measured for speed on their JOINs, meaning in some cases, it&#8217;s faster to do 20 simple queries than one complex one, or build a long and scary chain of &#8220;OR x=a OR x=b OR x=c OR x=d&#8230;&#8221;  Watching WordPress code in action is really fun for me, but watching <a href='http://osnews.com'>OSNews</a> work knowing what I now know about how much work PHP can cram into its threads is even more fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/osnews-vs-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How To REALLY Survive Digg on a Shared Host</title>
		<link>http://www.firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/</link>
		<comments>http://www.firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 22:48:29 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Digg]]></category>
		<category><![CDATA[High Performance]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/How-To-REALLY-Survive-Digg-on-a-Shared-Host</guid>
		<description><![CDATA[After reading a ridiculous post on &#8220;surviving the Digg effect on a shared host,&#8221; (and then laughing ridiculously at it), I decided to write a real tutorial on real-live ways not only to survive the Digg effect, but also a &#8230; <a href="http://www.firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After reading a ridiculous post on &#8220;<a href="http://digg.com/programming/How_to_Survive_Digg_on_a_Shared_Host">surviving the Digg effect on a shared host</a>,&#8221; (and then laughing ridiculously at it), I decided to write a <i>real</i> tutorial on real-live ways not only to survive the Digg effect, but also a simple but powerful way to improve your site&#8217;s performance.  Read more within.</p>
<p><span id="more-92"></span><br />
The fact is, it&#8217;s rarely PHP that crashes a website.  It&#8217;s usually overloading MySQL and/or bandwidth limitations.  Obviously, we can&#8217;t do much about bandwidth.  If you&#8217;re on a really cool host, they may be psyched for your Digging or Slashdotting, but most are not particularly keen on you using too much processor, too much bandwidth, or too many MySQL connections.  Although MySQL is capable of amazing scaling, rarely do web hosts leverage it properly, and even if they did, rarely do most programmers know how to read into slow queries, find inefficient code like loops within loops, and debug a site performance before it&#8217;s too late.  </p>
<p>The site linked from Digg shares a very lame trick, let&#8217;s examine:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//put this code at the very beginning of your page, before anything else</span>
<span style="color: #000088;">$randomdigg</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$randomdigg</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thanks for visiting, but the site is under a great deal of 
stress due to being on the front page of Digg. 
Please try back in a few moments. Thanks!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ok, so essentially, approximately 25% of the time, the page will work, the other 75% of the time, the user will get the message and be asked to refresh later.  That&#8217;s really lame.  First off, unless you want your website to be functional only 25% of the time, you have to be there babysitting it when it hits front page.  Also, you need to remove this code.  But what if you wanted everything to happen automagically? What if your site could withstand a digging, a slashdotting, a redditing, an OSNews&#8217;ing, a Farking, whatever&#8230;. all at once, without being forewarned?   </p>
<p>Although there are lots of [[http://www.danga.com/memcached/|tools that can do magic for you]], you can leverage plain old PHP to do this  dirty work for you, and it&#8217;s easy to integrate into your site.  </p>
<p>Here&#8217;s the premise, we examine the referrer of the page, and if the page is from one or many domains that you specify, you build a cache ON REQUEST.  Then, you serve the cached version.  When the cache stales, say after minute or two, you refresh it, as needed, again, on request. And the best part is, it&#8217;s easy to do. </p>
<p>So, let&#8217;s review the code.  First, at the top of the page, let&#8217;s do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$rfr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_REFERER'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//get the referring site</span>
<span style="color: #000088;">$op</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$rfr</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'digg.com'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$op</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
<span style="color: #000088;">$cache</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/path/to/mysite/cache/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$postid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Let&#8217;s take it line by line.  First, we get the referring site.  If it is digg.com, we&#8217;re going to turn the cache on by setting $op to &#8220;do-cache.&#8221; Note that we preset the $op variable to null to prevent abuse.  Next, we define the file we&#8217;re going to use as the cache.  Since we might want to do this for any entry/page, we&#8217;ll give it a unique address.  Remember that you do not have to use .html as an extension, since it&#8217;s static code anyway. I&#8217;ve seen &#8220;id.cache&#8221;, &#8220;id.txt&#8221;, and even just &#8220;id&#8221;.  It doesn&#8217;t matter, it will be included in a PHP page and spit out as X/HTML anyway.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$fmt</span> <span style="color: #339933;">=</span> <span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fmt</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">180</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://mysite.com/cache/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fmt</span> <span style="color: #339933;">&gt;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1800</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
         <span style="color: #666666; font-style: italic;">//cache will reload if it's been reloaded </span>
         <span style="color: #666666; font-style: italic;">//in the last half hour</span>
	   <span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	   <span style="color: #000088;">$op</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This might seem overwhelming, but it&#8217;s really not.  Check it out.  If the cache exists, regardless of referrer, we&#8217;re going to check it.  The filemtime() function will tell us when the cache was last refreshed.  If it reports a time in the last 180 seconds (you can change that number), it will redirect you to the cache.  PHP will barely have to do any work, Apache will barely have to do any work, and MySQL will not be touched at all.  Almost any host can hang in there to serve static traffic like this.  </p>
<p>But what about if the cache is old?  Once your site is no longer getting hits every three minutes, for the next 27 minutes, it will blindly reload the cache.  It will keep the cache going as long as the page has been hit in the last 30 minutes.  After no one hits the cache for 30 minutes, it will go back to fully dynamic.  When someone hits the page from digg again, it will start the caching process again.  In this case, we&#8217;re going to let the cache rebuild.  Enter the next part of the code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">ob_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If the $op variable is set to &#8220;do-cache&#8221;, our mission is&#8230; uh&#8230; to build or rebuild the cache. So, we begin with two simple PHP standard functions, <i>ob_clean()</i> and <i>ob_start()</i>.  The &#8220;ob&#8221; in these functions stands for &#8220;output buffering.&#8221;  When you buffer your output, nothing is echoed by the script, but rather written to a buffer.  In short, it&#8217;s all stored up in memory for eventual dumping later.  Now we stop the caching scripts and just write our normal HTML via PHP and MySQL.    </p>
<p>At the end of the page &#8211; the very end, after your html element is closed, you&#8217;ll need this last bit.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;do-cache&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">@</span><span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #990000;">ob_get_flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What&#8217;s up with this? Again, if we&#8217;re building the cache, we&#8217;re getting the contents of the buffer, which contains all of our page.  Then we&#8217;re opening the cache file we specified above, and lastly, dumping the contents of the buffer into the cache file.  Our final action is to clear the buffer, which is unnecessary to us now anyway.  </p>
<p>That&#8217;s it.  Your cache is reloaded, and will be served for the next three minutes, after which it will reload the cache every 3 minutes until no one hits the site for 30 minutes.  Then it will go back to dynamic.  If another digg visitor comes, it will recache and serve the cache.  Having written several types of caching mechanisms for large sites myself, I can tell you this &#8220;cache on demand&#8221; method works.  On <a href="http://www4.osnews.com">OSNews v4</a>, we use this for things like user-specific RSS files, which aren&#8217;t plausibly built via cron jobs and, frankly, we don&#8217;t want to allow access to MySQL without limit.  They reload every 60 minutes, regardless of referer.  </p>
<p>If you maintain a site and have any concern about being Dugg, I encourage you to research some sort of caching mechanism.  Your web host will thank you, and you will be thankful for the maintained uptime and high hit count.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/how-to-really-survive-digg-on-a-shared-host/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Integers on the Intertubes</title>
		<link>http://www.firsttube.com/read/integers-on-the-intertubes/</link>
		<comments>http://www.firsttube.com/read/integers-on-the-intertubes/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 16:22:44 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Nerd]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/Integers-on-the-Intertubes</guid>
		<description><![CDATA[Some time ago, I wrote an application for my company. Like most weblets I&#8217;ve written, this used PHP and either MySQL or MSSQL for the backend. This particular application logged all phone calls. As part of the record, it would &#8230; <a href="http://www.firsttube.com/read/integers-on-the-intertubes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some time ago, I wrote an application for my company.  Like most weblets I&#8217;ve written, this used PHP and either MySQL or MSSQL for the backend.  This particular application logged all phone calls. As part of the record, it would record the caller&#8217;s account number, which is a 5 or 6 digit integer.</p>
<p>So, I got a phone call from the director of our customer contact department this week.  He was concerned about the reports.  He made a decision last week that when a call came in that was a lead &#8211; in other words, a non-customer, that his people would fill the phone number from the caller ID into the account number field.  But when he ran his export reports, he found that hisn techs had entered this phone number for ALL of the calls: 429-496-7295.  That&#8217;s weird, he said.  So he called me and asked why that was.  I checked all the calls and most were from one woman, so my first instinct was &#8220;Check if her browser has autocomplete turned on&#8221;.  But he swore that he tried it too and gotten the same result.</p>
<p>I checked the database and sure enough, it was right there: 429-496-7295, in all of the fields.  So I went back to the code.  In short, I took the input from the form, and declared it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$accountnum</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'accountnum'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pretty straightforward: explicitly declare the type.  So, I started my debugging by attempting to manually enter the data into the database.  Sure enough: the account key field showed this: 4294967295.</p>
<p>So, I went back to the PHP and started by dumping out the raw SQL query:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">INSERT INTO calls <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'4294967295'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>What? So the database automatically converts it to this weird phone number and PHP does too?  Suddenly it occured to me. One of the benefits of 64-bit computing is the ability to address more memory.  There are limits to what can be done in 32-bit computing, and one is that <a href="http://en.wikipedia.org/wiki/Integer_(computer_science)">integers have a limit</a>!  In this case, a database field called &#8220;integer&#8221; is limited to numbers between -2,147,483,648 and +2,147,483,647.  It just so happens that the number is the same length as a US phone number &#8211; 10 digits.  Changing the db field to &#8220;BIGINT&#8221; allowed me to manually run the SQL query and it worked.  But the app still didn&#8217;t.</p>
<p>PHP&#8217;s int() and (int) $var syntaxes both conform to the integer limit.  So I devised a work around:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ac</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'accountnum'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ac</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ac</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$ac</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>It&#8217;s not gorgeous, but it will more than suffice for an internal app.  We web programmers don&#8217;t usually have to deal with big integers, so it&#8217;s totally possible that web developers would never have had occasion to handle a situation like this.  Here&#8217;s looking forward to native 64-bit for our next server, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/integers-on-the-intertubes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP vs. ASP.NET</title>
		<link>http://www.firsttube.com/read/php-vs-aspnet/</link>
		<comments>http://www.firsttube.com/read/php-vs-aspnet/#comments</comments>
		<pubDate>Fri, 27 Apr 2007 08:27:33 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/PHP-vs-ASPNET</guid>
		<description><![CDATA[We have a new web-based client portal application we are going to use for my company extranet. However, because it was originally designed to be a hosted application, there are several variables involved in all areas that don&#8217;t apply to &#8230; <a href="http://www.firsttube.com/read/php-vs-aspnet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We have a new web-based client portal application we are going to use for my company extranet.  However, because it was originally designed to be a hosted application, there are several variables involved in all areas that don&#8217;t apply to us, since we host it ourselves. </p>
<p>When using said portal, every URL looks something like: </p>
<p>domain.com/login.aspx?QS=jasbndfiaubnfoaeuifwoeifbwfe</p>
<p>The only difference is that the &#8220;QS&#8221; GET variable is even longer.  I made the request of our developers to get rid of this query string for the login page, and the login page only.  This is what that code looks like in PHP, inserted at line 1. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QS'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
     <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QS'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'jasbndfiaubnfoaeuifwoeifbwfe'</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
That&#8217;s it.  One line of code.  In ASP.net, this cost me 3 hours of developer time.  THREE hours. </p>
<p>Then I asked our old developers to make a change to their code.  It was doing a check in login if they are customers from the new app or the old one.  If they are old, it processes the login.  If it&#8217;they are new, it gives them an error message.  So I said, instead of giving them the error, let&#8217;s redirect them to /new-directory/login.aspx?email=[base64_encoded email]&#038;password=[base64_encoded password]. </p>
<p>This is that code in PHP: </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$is_new</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
     <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: /newdirectory/login.aspx?email=&quot;</span>
<span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;password=&quot;</span>
<span style="color: #339933;">.</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//process login</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
This cost me 2 hours at $165.  Am I getting taken for a ride? I keep telling them &#8211; this would take 30 seconds in PHP.  And they tell me, yes but ASP.net doesn&#8217;t work that way, and we need to change the web.config, and we need to recompile the entire site, etc, etc.  If it were just one vendor, I&#8217;d be more suspicious, but two separate, unrelated developers are giving me crazy quotes like this.  </p>
<p>I hear people bitch about PHP online ad nauseum.  Every time I see real code, it appears PHP is FAR faster and far more friendly when it comes to customization.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/php-vs-aspnet/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP Lesson 1: Pretty URLs!</title>
		<link>http://www.firsttube.com/read/php-lesson-1-pretty-urls/</link>
		<comments>http://www.firsttube.com/read/php-lesson-1-pretty-urls/#comments</comments>
		<pubDate>Thu, 28 Sep 2006 17:27:34 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[tubecode]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/PHP-Lesson-1-Pretty-URLs</guid>
		<description><![CDATA[I am going to start a new practice here. Every now and again I&#8217;m going to post some PHP code with some explanation. Today, I&#8217;m going to write about what I&#8217;ve been calling &#8220;pretty URLs&#8221; and how to create and &#8230; <a href="http://www.firsttube.com/read/php-lesson-1-pretty-urls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am going to start a new practice here.  Every now and again I&#8217;m going to post some PHP code with some explanation.  Today, I&#8217;m going to write about what I&#8217;ve been calling &#8220;pretty URLs&#8221; and how to create and manage them in PHP.</p>
<p>PHP includes a variable in the superglobal scope $_SERVER called &#8220;PATH_INFO.&#8221;  PATH_INFO includes information entered after the name of the requested script.</p>
<p>Let&#8217;s use <a href='http://firsttube.com'>firsttube.com</a> as an example.  The URL of a story is constructed as such:</p>
<p>http://firsttube.com/read.php/[id]/[url_friendly_title].html</p>
<p>The story is also accessible as /read.php?id=[id]</p>
<p>So how do we construct this so-called &#8220;pretty URL?&#8221; Using PATH_INFO.  Read on for details.<br />
<span id="more-322"></span><br />
Knowing the URL, we will use some code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</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>
	<span style="color: #000088;">$getvars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$null</span><span style="color: #339933;">,</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$getvars</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Let&#8217;s review piece by piece.</p>
<p>First, we find out if there is PATH_INFO set.  This is information BEFORE a question mark, so it doesn&#8217;t include GET variables.  Then, we use the standard explode() function to break up the PATH_INFO at the &#8220;/&#8221; sign, typical in a URL.  It fills the &#8220;getvars&#8221; array, which I&#8217;ve arbitrarily named, it could be anything.</p>
<p>Now, the first element is always NULL in this sense, but the second element is the id we had before.  And the third element is the title, which is something like title_of_the_post.html.  In another post, I&#8217;ll discuss sanitizing your title.</p>
<p>So what have you discovered is that the &#8220;title.html&#8221; portion is useless.  It&#8217;s there solely to please search engines and users who care. Try it.  All that matters is the number.  There are reasons why you&#8217;d validate the title, for example, so people don&#8217;t link to http://yoursite.com/storyID/your_mother_is_cow.html and have it be a valid URL.  But for now, let&#8217;s keep it simple.</p>
<p>Next is just to construct a linked URL that you like.  Perhaps your database tracks date.  You could make a URL http://yoursite.com/index.php/2006/09/28/1558.html.  Then do a little magic:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</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>
	<span style="color: #000088;">$getvars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$null</span><span style="color: #339933;">,</span><span style="color: #000088;">$year</span><span style="color: #339933;">,</span><span style="color: #000088;">$month</span><span style="color: #339933;">,</span><span style="color: #000088;">$day</span><span style="color: #339933;">,</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$getvars</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strstr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.html&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then, after you fix the time, you can assemble the timestamp for SELECTing:</p>
<p>Let&#8217;s say you prefer the WordPress format, which is yoursite.com/year/month/title.html.  Create an extra field in the database called &#8220;title&#8221; and record the title as you generate your entry.  It becomes a permalink, uneditable, even if the title changes.  Or not.  That&#8217;s up to you.</p>
<p>Either way, using PATH_INFO truly puts you in control of the URLs on your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/php-lesson-1-pretty-urls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MobileQuo</title>
		<link>http://www.firsttube.com/read/mobilequo/</link>
		<comments>http://www.firsttube.com/read/mobilequo/#comments</comments>
		<pubDate>Mon, 14 Aug 2006 15:44:02 +0000</pubDate>
		<dc:creator>Adam S</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Eugenia]]></category>
		<category><![CDATA[MobileQuo]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://firsttubecom/read/MobileQuo</guid>
		<description><![CDATA[Eugenia released a little web-let called &#8220;MobileQuo&#8221; the other day, and it caught my eye. I downloaded it and hacked it up and made some changes. 1. This version is more secure &#8211; it won&#8217;t let the content of the &#8230; <a href="http://www.firsttube.com/read/mobilequo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://eugenia.blogsome.com">Eugenia</a> released <a href="http://eugenia.gnomefiles.org/2006/08/11/tuxtops-mobile/">a little web-let called &#8220;MobileQuo&#8221;</a> the other day, and it caught my eye.  I downloaded it and hacked it up and made some changes.  </p>
<p>1. This version is more secure &#8211; it won&#8217;t let the content of the feed break your HTML.  <b>Update</b>: Apparently, the desired behavior is to render the HTML, not to preserve the markup as markup, so the new version Eugenia has released reflects that change.  So code will be rendered, including javascript, so beware!!      <br />
2. This version outputs friendly errors.  The 1.0 version can fail if your php.ini isn&#8217;t set up right, or output a blank page if there are certain errors. <br />
3. This version is more portable and doesn&#8217;t rely on a particular PHP configuration.  <br />
4. Most differently, this version can cache the results.  This way, each reload won&#8217;t hammer an RSS feed.  Rather, the results can be cached for a perdiod and fed from cache, and then when the cache expires, it reloads the cache.  </p>
<p>The source code is here: <a href="http://dev.firsttube.com/mq/mobile.phps">MobileQuo</a>.   Note that you will need to upload a blank WRITABLE file in your MobileQuo directory.  Then just use the rest of the code from Eugenia <a href="http://eugenia.gnomefiles.org/2006/08/11/tuxtops-mobile/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firsttube.com/read/mobilequo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

