<?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>XDnet Web Hosting Blog &#187; injections</title>
	<atom:link href="http://xdnet.co.uk/blog/tag/injections/feed/" rel="self" type="application/rss+xml" />
	<link>http://xdnet.co.uk/blog</link>
	<description>Honest, Reliable Webhosting</description>
	<lastBuildDate>Fri, 11 May 2012 21:08:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Protecting yourself from MySQL Injections</title>
		<link>http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/</link>
		<comments>http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 23:07:46 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Top Tips]]></category>
		<category><![CDATA[injections]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://xdnet.co.uk/blog/?p=104</guid>
		<description><![CDATA[It seems like everyone is concerned about MySQL injections when it comes to programming, however their is an easy solution out there! Here is the functions I wrote and have been using for a good few months and I&#8217;ve never had any problems. &#60;?php // The SQL Input Function This validates whats  inputted and 'cleans' it. function SQL_Input($input, $is_numeric=FALSE){ if(is_numeric($input) == TRUE &#38;&#38; $is_numeric == TRUE){ [...]]]></description>
			<content:encoded><![CDATA[<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fxdnet.co.uk%2Fblog%2F2008%2F09%2F24%2Fprotecting-yourself-from-mysql-injections%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"  data-text="Protecting yourself from MySQL Injections" data-count="horizontal" data-via="xdnet"></a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div><p>It seems like everyone is concerned about MySQL injections when it comes to programming, however their is an easy solution out there! Here is the functions I wrote and have been using for a good few months and I&#8217;ve never had any problems.</p>
<blockquote><p> <code><span style="#000000;"><span style="#0000bb;">&lt;?php<br />
</span><span style="#ff8000;">// The SQL Input Function This validates whats <br />
inputted and 'cleans' it.<br />
</span><span style="#007700;">function </span><span style="#0000bb;">SQL_Input</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">, </span><span style="#0000bb;">$is_numeric</span><span style="#007700;">=</span><span style="#0000bb;">FALSE</span><span style="#007700;">){<br />
if(</span><span style="#0000bb;">is_numeric</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">) == </span><span style="#0000bb;">TRUE </span><span style="#007700;">&amp;&amp; </span><span style="#0000bb;">$is_numeric </span><span style="#007700;">== </span><span style="#0000bb;">TRUE</span><span style="#007700;">){ </span><span style="#ff8000;">// If it's a number and it's ment to be a number.<br />
</span><span style="#007700;">return </span><span style="#0000bb;">$input</span><span style="#007700;">;<br />
}else{ </span><span style="#ff8000;">// Anything else<br />
</span><span style="#007700;">return </span><span style="#0000bb;">serialize</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">); </span><span style="#ff8000;">// You can replace this for a base64,<br />
 but I like serialize's.<br />
</span><span style="#007700;">}<br />
}</span></span></code></p>
<p><span style="#ff8000;">// The SQL output function. This convets the stuff pulled from the <br />
SQL back to normal text.<br />
</span><span style="#007700;">function </span><span style="#0000bb;">SQL_Output</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">, </span><span style="#0000bb;">$is_numeric</span><span style="#007700;">=</span><span style="#0000bb;">FALSE</span><span style="#007700;">){<br />
if(</span><span style="#0000bb;">is_numeric</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">) == </span><span style="#0000bb;">TRUE </span><span style="#007700;">&amp;&amp; </span><span style="#0000bb;">$is_numeric </span><span style="#007700;">== </span><span style="#0000bb;">TRUE</span><span style="#007700;">){ </span><span style="#ff8000;">// If it&#8217;s a number and it&#8217;s ment to be a number.<br />
</span><span style="#007700;">return </span><span style="#0000bb;">$input</span><span style="#007700;">;<br />
}else{ </span><span style="#ff8000;">// Anything else<br />
</span><span style="#007700;">return </span><span style="#0000bb;">unserialize</span><span style="#007700;">(</span><span style="#0000bb;">$input</span><span style="#007700;">);<br />
}<br />
}</span></p>
<p><span style="#ff8000;">### Example ###<br />
/* In the next example I&#8217;m going to pull some data from a table called &#8217;table&#8217;. <br />
Here is some info about the table:<br />
ID - Should only be numbers.<br />
Text - Is some plain text.</span></p>
<p>And the input is:<br />
$_POST['ID'] - should be a number.<br />
$_POST['Text'] - is some general text.<br />
*/<br />
<span style="#0000bb;">$result </span><span style="#007700;">= </span><span style="#0000bb;">mysql_query</span><span style="#007700;">(</span><span style="#dd0000;">&#8220;SELECT * FROM &#8217;table&#8217; WHERE ID=&#8217;&#8221;</span><span style="#007700;">.</span><span style="#0000bb;">SQL_Input</span><span style="#007700;">(</span><span style="#0000bb;">$_POST</span><span style="#007700;">[</span><span style="#dd0000;">'ID'</span><span style="#007700;">], </span><span style="#0000bb;">TRUE</span><span style="#007700;">).</span><span style="#dd0000;">&#8220;&#8216; AND Text=&#8217;&#8221;</span><span style="#007700;">.</span><span style="#0000bb;">SQL_Input</span><span style="#007700;">(</span><span style="#0000bb;">$_POST</span><span style="#007700;">[</span><span style="#dd0000;">'Text'</span><span style="#007700;">], </span><span style="#0000bb;">FALSE</span><span style="#007700;">).</span><span style="#dd0000;">&#8220;&#8216;&#8221;</span><span style="#007700;">);<br />
while (</span><span style="#0000bb;">$row </span><span style="#007700;">= </span><span style="#0000bb;">mysql_fetch_assoc</span><span style="#007700;">(</span><span style="#0000bb;">$result</span><span style="#007700;">)) {<br />
echo </span><span style="#dd0000;">&#8216;&lt;strong&gt;ID:&lt;/strong&gt;&#8217;</span><span style="#007700;">.</span><span style="#0000bb;">SQL_Output</span><span style="#007700;">(</span><span style="#0000bb;">$row</span><span style="#007700;">[</span><span style="#dd0000;">'ID'</span><span style="#007700;">], </span><span style="#0000bb;">TRUE</span><span style="#007700;">).</span><span style="#dd0000;">&#8220;\n&#8221;</span><span style="#007700;">;<br />
echo </span><span style="#dd0000;">&#8216;&lt;strong&gt;Text:&lt;/strong&gt;&#8217;</span><span style="#007700;">.</span><span style="#0000bb;">SQL_Output</span><span style="#007700;">(</span><span style="#0000bb;">$row</span><span style="#007700;">[</span><span style="#dd0000;">'Text'</span><span style="#007700;">], </span><span style="#0000bb;">TRUE</span><span style="#007700;">).</span><span style="#dd0000;">&#8220;\n&#8221;</span><span style="#007700;">;<br />
}<br />
</span><span style="#0000bb;">?&gt;</span></p></blockquote>
<div class="bottomcontainerBox" style="">
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fxdnet.co.uk%2Fblog%2F2008%2F09%2F24%2Fprotecting-yourself-from-mysql-injections%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<g:plusone size="medium" href="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"></g:plusone>
			</div>
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;">
			<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"  data-text="Protecting yourself from MySQL Injections" data-count="horizontal" data-via="xdnet"></a>
			</div><div style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/" data-counter="right"></script></div>			
			<div style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/"></script></div>			
			</div><div style="clear:both"></div><div style="padding-bottom:4px;"></div>]]></content:encoded>
			<wfw:commentRss>http://xdnet.co.uk/blog/2008/09/24/protecting-yourself-from-mysql-injections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

