<?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>ZaneHooper.com &#187; Web Tutorials</title>
	<atom:link href="http://zanehooper.com/blog/category/web-tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://zanehooper.com</link>
	<description>Web developer, designer, and Internet Entrepreneur</description>
	<lastBuildDate>Sat, 17 Dec 2011 21:52:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Security: Part 1 &#8211; SQL Injections</title>
		<link>http://zanehooper.com/blog/php-security-part-1-sql-injections.html</link>
		<comments>http://zanehooper.com/blog/php-security-part-1-sql-injections.html#comments</comments>
		<pubDate>Mon, 12 Jul 2010 02:14:28 +0000</pubDate>
		<dc:creator>Zane Hooper</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Tutorials]]></category>

		<guid isPermaLink="false">http://zanehooper.com/?p=21</guid>
		<description><![CDATA[One of a web developer&#8217;s biggest issues: security. If you don&#8217;t want your data stolen or your user&#8217;s redirected to other sites, there&#8217;s a lot of things you must go through to correct these problems. One of the best ways I find to be able to make a secure website is to try and find [...]]]></description>
			<content:encoded><![CDATA[<p>One of a web developer&#8217;s biggest issues: security. If you don&#8217;t want your data stolen or your user&#8217;s redirected to other sites, there&#8217;s a lot of things you must go through to correct these problems.</p>
<p>One of the best ways I find to be able to make a secure website is to try and find possible insecurities in OTHER websites (AKA, hacking). Try and go to a website and put a few hours into finding a security problem. Maybe your website isn&#8217;t secure against this?</p>
<p><strong>Part 1</strong> &#8211; <em>SQL Injections</em></p>
<p>SQL Injections are one of a programmer&#8217;s biggest nightmares. SQL Injections can be used to steal, delete, or edit data that is supposed to be protected. Like you can use SQL for your websites, SQL might also be able to be injected into your code. Let&#8217;s take a normal login form, for instance:</p>
<blockquote>
<pre>&lt;form method="post"&gt;
&lt;label for="username"&gt;Username:&lt;/label&gt;&lt;input type="text" name="username" id="username" /&gt;
&lt;label for="password"&gt;Password:&lt;/label&gt;&lt;input type="password" name="pass" id="password" /&gt;
&lt;/form&gt;</pre>
</blockquote>
<p>This simple little script will give us a login form. Now the PHP side of things will do something like so:</p>
<blockquote>
<pre>&lt;?php</pre>
<pre>$username = $_POST['username'];</pre>
<pre>$password = $_POST['pass'];</pre>
<pre>$user = mysql_fetch_array( mysql_query( "SELECT `id` FROM `users` WHERE `username` = '{$username}' AND `password` = '{$password}' LIMIT 1" ) );</pre>
<pre>?&gt;</pre>
</blockquote>
<p>Simple enough, right? Maybe you encrypt your password (which we will talk about in another part), but that&#8217;s beside the point.</p>
<p><strong>The Problem: </strong></p>
<p><strong> </strong>Now a hacker would enter something like this into the username field: &#8216; OR &#8217;1&#8242; = &#8217;1&#8242;# and then the query would look like so: <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;"> SELECT `id` FROM `users` WHERE `username` = &#8221; OR &#8217;1&#8242; = &#8217;1&#8242;#&#8217; AND `password` = &#8216;{$password}&#8217; LIMIT 1</span></p>
<p>This would allow the hacker to access accounts without even having a password to the account. The # escapes the rest of the query so that SQL doesn&#8217;t take it into account.</p>
<p><strong>The Fix</strong></p>
<p>Now to fix this problem we have to &#8220;escape&#8221; the data. In PHP, a &#8220;\&#8221; before an apostrophe. I use a global clean so I don&#8217;t forget to clean out any inputs. This cleans out ALL cookie, session, POST, GET, and REQUEST data.</p>
<p><em>The Function:</em></p>
<blockquote>
<pre><em>
<div id="_mcePaste"><span style="font-style: normal;">function Clean( $var )</span></div>
<div id="_mcePaste"><span style="font-style: normal;">{</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">if( is_array( $var ) )</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">{</span></div>
<div id="_mcePaste" style="padding-left: 60px;"><span style="font-style: normal;">foreach( $var as $key =&gt; $val )</span></div>
<div id="_mcePaste" style="padding-left: 60px;"><span style="font-style: normal;">{</span></div>
<div id="_mcePaste" style="padding-left: 90px;"><span style="font-style: normal;">$var[$key] = $this-&gt;Clean( $val );</span></div>
<div id="_mcePaste" style="padding-left: 60px;"><span style="font-style: normal;">}</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">}</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">elseif( is_string( $var ) )</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">{</span></div>
<div id="_mcePaste" style="padding-left: 60px;"><span style="font-style: normal;">$var = str_replace( '\&amp;', '&amp;', escapeshellcmd( htmlentities( $var ) ) );</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">}</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">else return;</span></div>
<div id="_mcePaste" style="padding-left: 30px;"><span style="font-style: normal;">return $var;</span></div>
<div id="_mcePaste"><span style="font-style: normal;">}</span></div>

</em></pre>
</blockquote>
<p><span style="font-style: normal;">This function grabs $var and cleans all of its values, returning the sanitized variable. The escapeshellcmd(  ) function cleans different SQL-dangerous values,while the htmlentities(  ) function cleans things like &#8220;&lt;&#8221; or &#8220;&gt;&#8221; (HTML Entities). The use of the Clean(  ) function:</span></p>
<pre><span style="font-style: normal;">
<pre>
<blockquote><address><span style="font-style: normal;">$check = array(</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_ENV',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_GET',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_POST',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_FILES',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_COOKIE',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_REQUEST',</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">'_SESSION'</span></address>
<address><span style="font-style: normal;">);</span></address>
<address><span style="font-style: normal;">
</span></address>
<address><span style="font-style: normal;">foreach( $check as $key =&gt; $elm )</span></address>
<address><span style="font-style: normal;">{</span></address>
<address><span style="white-space: pre;"><span style="font-style: normal;">	</span></span><span style="font-style: normal;">${$key} = Clean( ${$key});</span></address>
<address><span style="font-style: normal;">}</span></address>
</blockquote>
</pre>
<p></span><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;">This example will clean all inputs to DB friendly values! This also cleans out things like &lt;script&gt; or &lt;a&gt; that could possibly lead to dangerous outputs.</span></pre>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif;"><span style="line-height: 19px; white-space: normal;"><em>Up Next: </em><strong>PHP Security: Part 2 &#8211; Protecting vulnerable files</strong></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://zanehooper.com/blog/php-security-part-1-sql-injections.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Tutorial: Internet Explorer (IE) iframe</title>
		<link>http://zanehooper.com/blog/web-tutorial-internet-explorer-ie-iframe.html</link>
		<comments>http://zanehooper.com/blog/web-tutorial-internet-explorer-ie-iframe.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 15:33:55 +0000</pubDate>
		<dc:creator>Zane Hooper</dc:creator>
				<category><![CDATA[Web Tutorials]]></category>

		<guid isPermaLink="false">http://zanehooper.com/?p=17</guid>
		<description><![CDATA[I recently ran into a problem while trying to add an iframe with a transparent background in IE. CSS didn't seem to apply to the iframe when I was working with it (at least not very well). What we'll be fixing:

Allowing a background to be set with CSS or a transparent background
Removing borders from around the iframe (they look like crap)]]></description>
			<content:encoded><![CDATA[<p>I recently ran into a problem while trying to add an iframe with a transparent background in IE. CSS didn&#8217;t seem to apply to the iframe when I was working with it (at least not very well). What we&#8217;ll be fixing:</p>
<ol>
<li>Allowing a background to be set with CSS or a transparent background</li>
<li>Removing borders from around the iframe (they look like crap)</li>
</ol>
<p><strong>The Background</strong></p>
<p><strong> </strong>In Internet Explorer, if you try to add a background (or have a transparent background) with your page&#8217;s CSS it doesn&#8217;t work. Instead, it keeps a white, boring background from the iframe (assuming the iframe has no background set). This little code will fix this problem, allowing transparent or colored backgrounds to be set through CSS.</p>
<p>Inside of your &lt;body&gt; tag in the HTML of the iframe, set the background style to &#8220;inherit&#8221; (&lt;body style=&#8221;background:inherit;&#8221;&gt;) and you can have a background using CSS from <em>your</em> page. It&#8217;s that simple.</p>
<p><span style="text-decoration: underline;"><em>Note:</em></span><em> If you are making a transparent background, you need to add allowtransparency=&#8221;true&#8221; to the &lt;iframe&gt; tag as one of its attributes.</em></p>
<p><span style="text-decoration: underline;"><em>Note:</em></span><em> If you want to make this iframe of a page that you cannot edit, look into using PHP to modify the &lt;body&gt; tag.</em></p>
<p><strong>The Border</strong></p>
<p>This one is just as simple, and can be done straight from the HTML. Add to the &lt;iframe&gt;&#8217;s attributes the following: frameborder=&#8221;0&#8243;</p>
]]></content:encoded>
			<wfw:commentRss>http://zanehooper.com/blog/web-tutorial-internet-explorer-ie-iframe.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

