Questions answered by this recipe
This recipe provides a captcha capability that can be embedded into forms used by PmWiki. The captcha recipe works by displaying a random sequence of digits as part of an input form, and prompting the visitor to enter the digits into a text field in the form. Here is an example:
On systems that support it, the digits will be displayed as a distorted graphic image to increase the difficulty of an automated system determining the correct sequence. For PHP sites that don't have image manipulation support, the digits are displayed as plain text (this will still defeat a substantial number of robots).
To use this recipe in a typical setup:
Now, any request (even if you are authenticated) to save a page that doesn't contain a valid captcha code will be denied (with an opportunity to re-submit the request with the correct code).
Enabling captcha as described in the section made it so that I couldn't edit any of my pages without having to include a captcha code input on the edit form, and filling it out every time (lame!). There are various approaches to selectively enabling captcha.
Turn off captcha if you have edit permission
Turns off captcha if you're logged in and have edit permissions:
$EnablePostCaptchaRequired = 1; if (CondAuth($pagename,'edit')) $EnablePostCaptchaRequired = 0; include_once("$FarmD/cookbook/captcha.php");
Enable for specific pages
Enables for specific named pages, if you have edit permissions.
if (($pagename=='MyPage1' || ($pagename=='MyPage2')) && $action != 'edit') $EnablePostCaptchaRequired = true; include_once("$FarmD/cookbook/captcha.php");
Disable captcha in later processing
by ari October 29, 2008, at 12:21 PM EDT
Turn off captcha completely for edit (if you only want it to work for commentboxes, for example), after captcha is already enabled, add this code within appropriate conditional statements:
$EditFunctions = array_diff($EditFunctions, array('RequireCaptcha') );
Loading a new captcha image
by Ian MacGregor
If your visitors are having a difficult time reading the captcha, you may want to add text somewhere in the page which gives the visitor a good method for "re-generating" the captcha. I added this to my Site.EditForm:
"If the captcha is too difficult to read, click the Send button and try again."
as that will re-generate the captcha while preserving the text the visitor might have already entered into the form.
Displaying image captcha, not a text captcha
by Ian MacGregor
If you're finding that the captcha is displayed as text instead of an image, you can try adding this to the local/config.php:
This seemed to force the captcha to display as an image instead of text on my server.
Integration with Mailform2
To integrate with Cookbook.Mailform2, add the following line *after* you load the captcha.php, and before loading mailform2.php, in 'local/config.php'. Then ensure that any mail form you use has the captcha code shown above (i.e. "
include_once("$FarmD/cookbook/captcha.php"); ... $Mailform2Disabled = $Mailform2Disabled || !IsCaptcha(); ... include_once("$FarmD/cookbook/mailform2.php");
See discussion at Captcha-Talk