<?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>bitblogr.com &#187; php</title>
	<atom:link href="http://www.bitblogr.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bitblogr.com</link>
	<description>design, tutorials, inspiration, creativity</description>
	<lastBuildDate>Sat, 05 Jun 2010 17:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Autodeclaring form data variables</title>
		<link>http://www.bitblogr.com/how-to/autodeclaring-form-data-variables/</link>
		<comments>http://www.bitblogr.com/how-to/autodeclaring-form-data-variables/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 08:56:43 +0000</pubDate>
		<dc:creator>Opeyemi Obembe</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[globals]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sessions]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.bitblogr.com/?p=182</guid>
		<description><![CDATA[Here is a very useful simple snippet that saves a lot of coding time. Picture a feedback form with 3 fields: name, email and feedback. When handling the form results, you&#8217;d want to do something like this; $name = $_POST['name']; $email = $_POST['email']; $feedback = $_POST['feedback']; and then use the declared variables in whatever way [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;margin-right:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fautodeclaring-form-data-variables%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fautodeclaring-form-data-variables%2F&amp;source=bitblogr&amp;style=normal&amp;service_api=R_2574ec2cdf93a9dc24a80c02f8d96a25&amp;hashtags=cookies,database,form,globals,mysql,php,sessions,variable" height="61" width="50" /><br />
			</a>
		</div>
<p>Here is a very useful simple snippet that  saves a lot of coding time.<br />
Picture a feedback form with 3 fields: name, email and feedback. When handling the form results, you&#8217;d want to do something like this;<span id="more-182"></span></p>
<pre>$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedback'];</pre>
<p>and then use the declared variables in whatever way you want to &#8211; send to an email, put in a db or both. (By the way, please note that that is as basic as it is. Of course you will want to validate the values and probably escape or so).</p>
<p>Now what if you have up to 50 fields in your form? You will auto-declare them one by one like the above? Nah. A way to auto-declare the variables based on their respective key in the $_POST (or $_GET or any super global array) is this:</p>
<pre>foreach ($_POST as $k =&gt; $v) {
	$$k = $v;
}</pre>
<p>Notice the line &lt;b&gt;$$k = $v&lt;/b&gt;? It is called <a href="http://php.net/manual/en/language.variables.variable.php">variable variables</a>. It enables setting and using variable names dynamically.</p>
<p>Now, one important note! If you have &#8216;register_globals&#8217; turned on in your PHP configuration, PHP will automatically declare superglobal variables for you so no need of the snippet above. It is however recommended that &#8216;register_globals&#8217; is turned off for security reasons. With register_globals on, hackers can easily bypass parts of your script that rely on variable conditional statements by injecting the URL. Even the script above should be used to auto-declare only necessary superglobals like GET and POST and not COOKIES and SESSIONS. And when used, the variable values should still be validated for inappropriate data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitblogr.com/how-to/autodeclaring-form-data-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Preventing forms from bots &#8211; the blank method</title>
		<link>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/</link>
		<comments>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 01:19:18 +0000</pubDate>
		<dc:creator>Opeyemi Obembe</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bitblogr.com/?p=164</guid>
		<description><![CDATA[One of the challenges web designers and developers face is preventing forms from automated programs that disguise as humans and fill forms (call them bots). And needless to say, this bots can really be a nuisance &#8211; posting bad content, stealing data and doing all kind of weird stuffs. And so there was Captcha &#8211; [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;margin-right:10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fpreventing-forms-from-bots-the-blank-method%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.bitblogr.com%2Fhow-to%2Fpreventing-forms-from-bots-the-blank-method%2F&amp;source=bitblogr&amp;style=normal&amp;service_api=R_2574ec2cdf93a9dc24a80c02f8d96a25&amp;hashtags=bot,captcha,CSS,development,php" height="61" width="50" /><br />
			</a>
		</div>
<p>One of the challenges web designers and developers face is preventing forms from automated programs that disguise as humans and fill forms (call them <strong>bots</strong>). And needless to say, this bots can really be a nuisance &#8211; posting bad content, stealing data and doing all kind of weird stuffs. And so there was <a href="http://en.wikipedia.org/wiki/Captcha&quot;Captcha"></a><a href="http://en.wikipedia.org/wiki/Captcha" target="_blank">Captcha</a> &#8211; a test to verify human response and prevent such bots.</p>
<p><span id="more-164"></span><br />
But then, personally I don&#8217;t like Captchas. Ok, I love <a href="http://recaptcha.net" target="_blank">reCaptcha</a>, but just as an idea for <a href="http://recaptcha.net/learnmore.html" target="_blank">digitalizing books</a>; nothing more. Since I&#8217;m not a big fan then, I figured someone somewhere may as well not be, so I decide to go the way of a different technique for validating my forms. I call it the <em>blank method</em>. (No, that&#8217;s not an &#8216;official&#8217; name :P)</p>
<p>To start with, the technique is not my idea. Actually, an attribution to the owner should come somewhere here but I just can&#8217;t remember where I came across it as its really been long. That said, also note that the technique is not 100% fool proof. While it may save your form from bots, it won&#8217;t save you from real human spammers that are around to purposely junk up your site and be a nuisance.</p>
<p>So what is it all about? The technique is based on the fact that bots can&#8217;t see. A text input field is created somewhere in the form and labelled “Don’t fill” or “Leave Blank” or anything to tell the user to leave the input box empty. The human user filling the form will do just this  i.e.  ignore the field but a <strong>bot</strong> will fill in something there. During validation, the field can then be checked for content. If there exist a content for it, it sure is a bot (or probably a stubborn human).</p>
<p>Here is an overview of what it looks like:</p>
<h2>[The html code]</h2>
<pre>&lt;form method="post" action="submitpage.php"&gt;
    &lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name" /&gt;    
    &lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="email" /&gt;
    &lt;label&gt;Leave Blank&lt;/label&gt; &lt;input type="text" name="foo" /&gt;
    &lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;</pre>
<h2></h2>
<h2>[The server-side validation (I use PHP)]</h2>
<pre>&lt;?php
$foo = trim($_POST['foo']);
if(empty($foo))
{
  //ok, didnt fill anything in the field
  //most def a human
}
else
{
  //filled in something
  //bot! Kick out!
}
?&gt;</pre>
<p><img class="size-full wp-image-162 alignnone" title="unstyled.gif" src="http://www.bitblogr.com/wp-content/uploads/2009/12/unstyled.gif" alt="unstyled.gif" width="263" height="163" /></p>
<h2>And that&#8217;s all.</h2>
<p>Let&#8217;s tweak things a little bit to make the form more beautiful. But not just only beautiful. What about we hide the &#8216;Leave Blank&#8217; field with CSS so that normally users wont even see or notice it (and consequently won&#8217;t fill it)? Bots on the other hand will still &#8216;see&#8217; it and fill it.</p>
<h2>[The CSS]</h2>
<pre>/*resets*/
.nodisplay {
    display:none
} 

/*form*/
form label {
    float:left;
    text-align:right;
    padding-right:10px;
    width:100px
}

form input.txt {
    width:150px;
    padding:3px;
    border:1px solid #ACA899
}

form input.txt:hover, form input.txt:focus {
    border:1px solid #102336;
}</pre>
<h2>[The new html]</h2>
<pre>&lt;form method="post" action="submitpage.php"&gt;
    &lt;p&gt;&lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name" class="txt" /&gt;&lt;/p&gt;
    &lt;p&gt;&lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="email" class="txt" /&gt;&lt;/p&gt;
    &lt;p class="nodisplay"&gt;&lt;label&gt;Leave Blank&lt;/label&gt; &lt;input type="text" name="foo" /&gt;&lt;/p&gt;
    &lt;p&gt;&lt;label&gt;&amp;nbsp;&lt;/label&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/p&gt;
&lt;/form&gt;</pre>
<p><img class="alignnone size-full wp-image-163" title="styled.gif" src="http://www.bitblogr.com/wp-content/uploads/2009/12/styled.gif" alt="styled.gif" width="245" height="124" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bitblogr.com/how-to/preventing-forms-from-bots-the-blank-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
