<?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>Developer Oracles &#187; php devlopment</title>
	<atom:link href="http://devoracles.com/tag/php-devlopment/feed" rel="self" type="application/rss+xml" />
	<link>http://devoracles.com</link>
	<description></description>
	<lastBuildDate>Sun, 21 Mar 2010 11:05:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Filter your variables easily but like a pro!</title>
		<link>http://devoracles.com/filter-your-variables-easily-but-like-a-pro/10</link>
		<comments>http://devoracles.com/filter-your-variables-easily-but-like-a-pro/10#comments</comments>
		<pubDate>Sun, 13 Jul 2008 16:42:22 +0000</pubDate>
		<dc:creator>Gary Illyes</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[email validation]]></category>
		<category><![CDATA[ip validation]]></category>
		<category><![CDATA[php devlopment]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Server Management]]></category>
		<category><![CDATA[validating input php]]></category>
		<category><![CDATA[variable filtering]]></category>
		<category><![CDATA[variable validation]]></category>

		<guid isPermaLink="false">http://devoracles.com/?p=10</guid>
		<description><![CDATA[How painful input validation is! Think about all the possible threats, combination of threats&#8230; think with the users&#8217; mind. It&#8217;s a pain. And usually who can write scripts which filters effectively the user inputs is considered a pro, without hesitation. Just because it&#8217;s hard to do it.
Take the following scenario: you have a text-field which [...]]]></description>
			<content:encoded><![CDATA[<p>How painful input validation is! Think about all the possible threats, combination of threats&#8230; think with the users&#8217; mind. It&#8217;s a pain. And usually who can write scripts which filters effectively the user inputs is considered a pro, without hesitation. Just because it&#8217;s hard to do it.<br />
Take the following scenario: you have a text-field which accepts text as user comment. You don&#8217;t want to let the user to use HTML in the comment box, and definitely not to allow the user to put javascript in the comment.<br />
So how do you sanitize the string you get? It&#8217;s a long and hard way. You would use RegExp to exclude some entities then some php inbuilt functions to encode the remaining or even better to strip tags.<br />
I show you an easier way:</p>
<pre name="code" class="php">
filter_var(’&lt;script&gt;alert('Hello');&lt;/script&gt;', FILTER_SANITIZE_STRING);
</pre>
<p>Done, the &lt;script&gt; tags will be stripped so the string will arrive in the database as alert(&#8216;Hello World&#8217;).<br />
There are many available filters, just to mention the most interesting ones:</p>
<ul>
<li>FILTER_SANITIZE_EMAIL &#8212; it sanitizes email address, strips characters which are not in conformance with the applicable <a href="http://tools.ietf.org/html/rfc2822">RFC</a> (link)</li>
<li>FILTER_SANITIZE_URL &#8212; whether the URL from the variable is in conformance with the applicable <a href="http://www.ietf.org/rfc/rfc1738.txt">RFC</a> (link)</li>
<li>FILTER_VALIDATE_IP &#8212; whether if the input is an IP address or not</li>
</ul>
<p>I recommend using the filter_var() function and its filters for two obvious reasons: it saves you a lot of headaches and saves you time. Even though the filter_var function was introduced only in php 5.2 the function is extremely useful and gives another reason for you of why to upgrade to php5 <img src='http://devoracles.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>For a complete reference please check <a href="http://www.php.net/manual/en/function.filter-var.php">php.net</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://devoracles.com/filter-your-variables-easily-but-like-a-pro/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
