|
Cookbook /
CaptchaSummary: Use captchas to prevent automated systems from modifying pages
Version: 2008-07-13
Prerequisites: pmwiki-2.2.0-beta46
Status:
Maintainer: Pm
Discussion: Captcha-Talk
Questions answered by this recipe
DescriptionThis 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). InstallationTo 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). Selectively Enable Captchaby overtones99 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 permissionby Hans 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 pagesby Randy Enables for specific named pages, if you have edit permissions.
if (($page=='MyPage1' || ($page=='MyPage2')) && $action != 'edit')
$EnablePostCaptchaRequired = true;
include_once("$FarmD/cookbook/captcha.php");
Disable captcha in later processingby 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 imageby 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 captchaby 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: $EnableCaptchaImage=1; This seemed to force the captcha to display as an image instead of text on my server. Integration with Mailform2To 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");
ContributorsCommentsSee discussion at Captcha-Talk User notes +5: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki. |