<?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>jobberBase dev blog &#187; How-to</title>
	<atom:link href="http://www.jobberbase.com/blog/category/how-to/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jobberbase.com/blog</link>
	<description>jobberBase is an open source job board that helps you set up a jobsite in minutes!</description>
	<lastBuildDate>Wed, 20 Oct 2010 10:22:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to implement reCAPTCHA</title>
		<link>http://www.jobberbase.com/blog/01-23-2008/how-to-implement-recaptcha/</link>
		<comments>http://www.jobberbase.com/blog/01-23-2008/how-to-implement-recaptcha/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 11:40:41 +0000</pubDate>
		<dc:creator>Filip</dc:creator>
				<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.jobberbase.com/blog/01-23-2008/how-to-implement-recaptcha/</guid>
		<description><![CDATA[If you haven&#8217;t been spammed by bots, yet, you probably will soon be  .
On jobber.ro, we use reCAPTCHA to prevent spam. It&#8217;s a hosted captcha provider and much more!
Step 1. Create an account with reCAPTCHA
Go ahead and create an account, download the PHP API (and copy recaptchalib.php in the _includes/ directory, and sign up [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t been spammed by bots, yet, you probably will soon be <img src='http://www.jobberbase.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> .<br />
On <a href="http://www.jobber.ro/">jobber.ro</a>, we use <a href="http://recaptcha.net/">reCAPTCHA</a> to prevent spam. It&#8217;s a hosted captcha provider and <a href="http://recaptcha.net/learnmore.html">much more</a>!</p>
<h3>Step 1. Create an account with reCAPTCHA</h3>
<p>Go ahead and create an account, <a href="http://recaptcha.net/plugins/php/">download the PHP API</a> (and copy <strong>recaptchalib.php</strong> in the <strong>_includes/</strong> directory, and <a href="http://recaptcha.net/api/getkey?app=php">sign up for an API key</a>.</p>
<h3>Step 2. Add reCAPTCHA when posting an ad</h3>
<p><strong>config.php</strong><br />
Define 2 constants, one for public and one for the private API key:</p>
<pre><code>define('CAPTCHA_PUBLIC_KEY', '12345_YOUR_PUBLIC_KEY');
define('CAPTCHA_PRIVATE_KEY', '12345_YOUR_PRIVATE_KEY');</code></pre>
<p>Also add the following line (find the other <strong>require_once</strong> lines), which includes the recaptcha library:</p>
<pre><code>require_once '_includes/recaptchalib.php';</code></pre>
<p><strong>_templates/publish-write.tpl</strong><br />
Right above the submit button&#8217;s fieldset, insert the following code:</p>
<pre><code>&lt;h2 class="publish_section"&gt;Anti-spam&lt;/h2&gt;
&lt;fieldset&gt;
  {literal}
    &lt;script type="text/javascript"&gt;
      var RecaptchaOptions = {
        theme : 'white',
        tabindex : 9
      };
    &lt;/script&gt;
  {/literal}
  {$the_captcha} &lt;span class="validation-error"&gt;{if $errors.captcha}
  &lt;img src="{$BASE_URL}img/icon-delete.png" alt="" /&gt;{/if}&lt;/span&gt;
&lt;/fieldset&gt;</code></pre>
<p><strong>page-write.php</strong><br />
On line 2, we generate the html code that displays the captcha in the template:</p>
<pre><code>$smarty-&gt;assign('the_captcha', recaptcha_get_html(CAPTCHA_PUBLIC_KEY));</code></pre>
<p>Next, we perform a simple validation when posting the ad. Find the following line:</p>
<pre><code>if ($_POST['action'] &amp;&amp; $_POST['action'] == 'publish')</code></pre>
<p>A couple of lines below it, after you initialize the <strong>$errors</strong> array, add this code:</p>
<pre><code>$resp = recaptcha_check_answer(CAPTCHA_PRIVATE_KEY,
$_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp-&gt;is_valid)
{
  $errors['captcha'] = 'Incorrect code';
}</code></pre>
<p>Then, we need to add the captcha validation in another section of page-write.php, the one that handles the ad edit. Find the following line and add the same code as above:</p>
<pre><code>else if ($_POST['action'] &amp;&amp; $_POST['action'] == 'edit'</code></pre>
<p>That should be it <img src='http://www.jobberbase.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jobberbase.com/blog/01-23-2008/how-to-implement-recaptcha/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

