<?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>humandoing software &#187; php</title>
	<atom:link href="http://blog.humandoing.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.humandoing.net</link>
	<description>better software for everyone</description>
	<lastBuildDate>Fri, 06 Jan 2012 16:17:20 +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>Your License To Code PHP Has Been Revoked</title>
		<link>http://blog.humandoing.net/2008/04/09/your-license-to-code-php-has-been-revoked/</link>
		<comments>http://blog.humandoing.net/2008/04/09/your-license-to-code-php-has-been-revoked/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 08:03:00 +0000</pubDate>
		<dc:creator>Daniel Wintschel</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rants]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://humandoing.net/past/2008/4/9/your_license_to_code_php/</guid>
		<description><![CDATA[It&#8217;s a typical story. Dan on a rescue mission, fixing a mess that some clown(s) left behind. PHP. No framework to speak of, riddled with SQL injection holes, a TABLE-based layout &#8211; and it doesn&#8217;t get any better from there. For the love of all things holy, why do people have to do stuff like [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a typical story. Dan on a rescue mission, fixing a mess that some clown(s) left behind. <span class="caps">PHP</span>. No framework to speak of, riddled with <span class="caps">SQL</span> injection holes, a <span class="caps">TABLE</span>-based layout &#8211; and it doesn&#8217;t get any better from there.</p>
<p>For the love of all things holy, why do people have to do stuff like this:</p>
<pre><code>$sql = "SELECT user_id,user_status FROM users WHERE user_name='$username' AND user_password='$p'";<br/>$r = mysql_fetch_assoc(mysql_query($sql));<br/></code></pre>
<p>For the record, <code>$username</code> and <code>$p</code> were just grabbed right out of <code>$_POST</code>.</p>
<p>If you spent 30 seconds to write even a crappy inefficient function to actually do something intelligent, not only would you not have code that&#8217;s riddled with <span class="caps">SQL</span> injection vulnerabilities (did I mention that this snippet of joy came out of a 3112 line file without a <span class="caps">SINGLE</span> comment?), but it might actually make your life easier because your code won&#8217;t suck so much &#8211; and you can stop repeating yourself.</p>
<p>I&#8217;m no 1337 <span class="caps">PHP</span> h4&#215;0r, but how about &#8211; oh, I don&#8217;t know &#8211; something like this:</p>
<pre><code>function fetch_associative_array_safely( $array ){<br/>  $sql = $array[0];<br/>  foreach ($array as $index =&gt; $value) {<br/>    $sql = str_replace( "?".$index, addslashes($value), $sql );<br/>  }<br/>  return mysql_fetch_assoc( mysql_query( $sql ) );<br/>}</code></pre>
<p>And just execute that bad boy like so:</p>
<pre><code>$r = fetch_associative_array_safely( <br/>      array( "SELECT user_id, user_status FROM users WHERE user_name='?1' AND user_password='?2'", <br/>             $username, $p) );</code></pre>
<p>It&#8217;s not overly elegant, beautiful or efficient. But I don&#8217;t think that really matters. It helps me to not repeat myself, and by golly &#8211; at least someone can&#8217;t drop tables from my database anymore. It&#8217;s a bit Rails-esque, at least as far the the <code>conditions</code> portion of <code>ActiveRecord::Base.find(...)</code>.</p>
<p>What do you think? I haven&#8217;t done any <em>significant</em> PHP coding in years.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humandoing.net/2008/04/09/your-license-to-code-php-has-been-revoked/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

