Captcha for b2evolution, explained
The original code for this is courtesy Keith McDuffee, his web site is located here. Keith wrote his plugin for WordPress, and since b2evolution didn't have any captcha code, I decided to implement his code on my b2evolution blog. I no longer use b2evolution for my production blog, but several people have asked for this, and after taking a second look, it really wasn't too hard to do.
Begin by downloading this zip archive. It contains the font used to create the captcha and authimage.php. Both of these files need to be uploaded to your root b2evo directory -- that would be the same directory that default.php is in, in case you get confused.
The next thing you will need to do is set up your blog to check to see if the code entered actually matches the captcha image. That's accomplished by the following changes to htsrv/comment_post.php:
Locate :
- require_once( dirname(__FILE__) . '/../b2evocore/_main.php' );
Immediately below that line put the following:
Then, further down, locate:
- // CHECK and FORMAT content
- //echo 'allowed tags:',htmlspecialchars($comment_allowed_tags);
- $original_comment = strip_tags($comment, $comment_allowed_tags);
- $comment = format_to_post($original_comment, $comment_autobr, 1);
- if( empty($comment) )
- { // comment should not be empty!
- errors_add( T_('Please do not send empty comment') );
- }
Immediately after that you need to put the following:
if (strlen($code) < 6)
$code = '';
if ( !checkAICode($code) )
errors_add( T_('Error: You have not entered the correct authorization code.') );
That's all for that file.Save it, close it.
The next change displays the captcha and the box for entering the code. Inside all of your skins directories should be a file named _feedback.php. Locate it, open it up, and look for something similar to this:
- <p>
- <label for="comment">< ?php echo T_('Your Comment'); ?></label>
- <br />textarea name="comment" id="comment" cols="70" rows="4" tabindex="4">
- </p>
Under that or wherever you would like your code and box to be displayed, you need to have this:
<input type="text" name="code" id="code" value="<?php echo ""; ?>" size="28" tabindex="4" />
<label for="code"><?php echo T_("Enter this code: "); ?></label>
<img src=".../../authimage.php?type=image" width="155" height="50" alt="authimage" class="authimage" />
</p>
You can save and close that file.
One big thing about using this... If a commenter enters an incorrect captcha code, they will see an error. At the point they hit their back button to re-enter the code, they may lose their comment. Because of that, I use, and reccommend that you also use a simple javascript onsubmit function to remind users to make sure they entered the code, and to doublecheck that it is correct.
Hope that helps out everyone who's been waiting for this.
With the recent birth of b2evolution 1.8 and the native captcha plugin that is included with it, I've discontinued comments on this post. Any remaining questions regarding the use of this should be directed to the b2evolution forums.
January 28th, 2005 · code · whoo · Comments (84)


