Using captchas with Project Steve Guttenberg
I've just committed some new code that allows you to intercept the comment posting process, so that you can implement a challenge-response system like a captcha to avoid comment spam.
In your $conf array you need to define two new keys:
- comment_post_validate_controls
- this is the name of a function that is called by the printCommentForm() function. It should return a string containing any extra HTML that you might want to insert into the comments form.
- comment_post_validate_function
- this is the name of a function that is called by the postComment() function. It should return a boolean value that tells postComment() whether or not it should allow the comment to be posted.
Here's how I implemented a captcha system using the new feature and captcha.net:
- check out the latest version of PSG from CVS.
- go to captchas.net and sign up for an account.
- download the CaptchasDotNet.php file in place it in your psg directory.
- open the script in which your $conf is located in an editor, and add the new keys like so:
$config[comment_post_validate_controls] = 'captchaControls'; $config[comment_post_validate_function] = 'captchaValidate';
- in the same file, insert this code:
require_once('CaptchasDotNet.php'); $CAPTCHA = new CaptchasDotNet( $YOUR_USERNAME, // client $YOUR_SECRET, // secret '/tmp/captchasnet-random-strings', // repository_prefix '3600', // cleanup_time 'abcdefghkmnopqrstuvwxyz', // alphabet '6', // letters '240', // width '80' // height ); function captchaControls() { global $CAPTCHA; printf( '<input type="hidden" name="captcha-random" value="%s" /> Please enter the letters in the image below into the input:<br /><br /> %s<br /><br /> <input type="text" name="captcha-text" /><br /><br /> <a href="%s">Click here for a phonetic spelling (MP3)</a><br /> <small>powered by <a href="http://captchas.net/">captchas.net</a></small><br /><br />', $CAPTCHA->random(), $CAPTCHA->image(), $CAPTCHA->audio_url() ); } function captchaValidate($comment) { global $CAPTCHA; return ($CAPTCHA->validate($_POST['captcha-random']) && $CAPTCHA->verify($_POST['captcha-text'])); }
The captcha works perfectly!
No more comments can be posted to this article.
| << Previous: Project Steve Guttenberg 1.12.0 | Next: Using Akismet with PSG >> |
Comments:
Posted by Greg (drakos7 (at) gmail dot com) on Friday, January 19, 2007
Perhaps I am just brain dead today, but I cannot find out where to sign up for the captcha.net account.
Posted by Greg (drakos7 (at) gmail dot com) on Friday, January 19, 2007
Posted by Alex on Thursday, February 22, 2007
http://captchas.net/registration/