Simple Captcha is the modified version of Drupal’s captcha module. This library will generate a simple captcha image with the specified noise and distortion ratios. The reason for using Drupal’s code base for this captcha library is because of its variety of font support, distortion and noise settings in the generated captcha image. AJAX based refresh for new set of words makes the library more attractive.
The combination of flexible architecture of CodeIgniter & Drupal’s expertise in GD libraries will make this module an essential ingredients for the registration pages.
Library file:
——————-
Place it inside /application/libraries/drupalcaptcha.php
Controller file:
————————
Place it inside /application/controllers/captcha.php
<?php
/**
* Controller Class which is used for Captcha Image display in user registration
*
* @verison 1.0
* @author Sastha L
*/
class Captcha extends Controller {
/**
* _constructor Controller
*/
function Captcha()
{
parent::Controller();
$this->load->library('drupalcaptcha');
$this->captcha = new drupalcaptcha();
}
/**
* Index Controller
*/
function index()
{
$this->captcha->createCaptcha();
}
/*
* Function to display Captcha image on page load
*/
function createNewImage()
{
$this->captcha->set_captcha_image();
}
/*
* Function to display the src during AJAX call
*/
function displayCaptcha($seed = '')
{
$this->captcha->get_captcha_image($seed);
}
}
/* End of file captcha.php */
/* Location: ./system/application/controllers/captcha.php */
?>
View File:
—————
Place it inside /application/views/captcha.php
<html>
<head>
[removed]config->site_url();?>js/jquery.js">[removed]
[removed]
var captcha_flag=false;
function ch_captcha(type,seed)
{
var url='';
url='<?php echo $this->config->site_url();?>';
var token='';
if(captcha_flag==true)
return;
captcha_flag=true;
var urls='';
if(type==2 && seed==null)
{
//token_1=$("#edit-captcha-token").val();
urls=url+"captcha/createNewImage";
}
else
urls=url+"captcha/displayCaptcha/"+seed;
$.ajax({
type: "GET",
url: urls,
success: function(msg){
captcha_flag=false;
if(msg!="")
{
if(type==2 && seed==null)
{
var temp=msg;
var pos=temp.indexOf("^");
if(pos>1)
{
var arr=Array();
arr=temp.split("^");
seed=arr[0];
token=arr[1];
$("#img_cap").attr("src",""+url+"captcha/displayCaptcha/"+seed);
$("#edit-captcha-token").val(token);
}
//ch_captcha(1,seed);
}
}
},
error: function(msg){
captcha_flag=false;
}
});
}
[removed]
</head>
</body>
<table width="686" height="115" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" align="right"></td>
<td colspan="3">
<input type="hidden" name="captcha_token" value="<?php echo md5(mt_rand()); ?>" />
<img >config->site_url('captcha')?>" id="img_cap" alt="no-image"/><br />
<a>Show new characters</a>
<div class="bottomspacer"></div> </td>
</tr>
<tr>
<td valign="top" align="right">Security Verification</td>
<td width="150" valign="top">
<?php
if(isset($captchaResponse))
{
$captchaResponse = $captchaResponse;
}else{
$captchaResponse = '';
}
?>
<input type="text" value="<?=$captchaResponse?>" size="25" id="edit-captcha-response" name="captcha_response" maxlength="5"/></td>
<td width="156"><span class="helpcontent">Type the characters you see in the picture above. Letters are not case-sensitive
</span></td>
</tr>
</table>
</body>
</html>
This will generate a simple captcha image.
