Tuesday, August 30, 2011

Drupal - Simple captcha


Hi,


This article is about using custom captcha in Drupal. This one is a custom created module in Drupal. This is developed under Drupal 6.20 environment. I am sure if you get a feel of it you can modify it for other versions as well.

You can get the code from here.

This is how it would look like:


Code & Explanation:

After you have downloaded the module. Install it in your project. Once done that, all you have to do is to put the following lines of code in your page form:



<img src="your_project/simplecaptcha/<?php echo rand(); ?>" id="cptcha">

Try a <a href="javascript:void(0)" onclick="jQuery('#cptcha').attr('src','your_project/simplecaptcha/' + ((Math.random()*11)))">different word</a>

 <input type="text" name="security_code" />


Now after the form is submitted, place the following code for validating the security code with the captcha image:

if(!validate_simplecaptcha($_REQUEST['security_code'])){
           // invalid code
}else{
          // valid code
}

That's it. Let me know if you need more help.

Download: simplecaptcha.zip




No comments:

Post a Comment