Here
is the latest CakePHP Captcha component for CakePHP Version 2.x. Compatible up
to CakePHP version 2.5.3.
NOTE:For best Image
Captcha results this component requires GD and Freetype support
enabled. Please check your phpinfo() to know whether your server supports
this (See image below). Contact your hosting provider if any of these libraries
is not enabled.
Update
– Sep 25, 2013
§
Supports Image and Simple
Math captcha
§
Works
without GD Truetype font support (NOT RECOMMENDED though)
§
Default
and Random themes for Image Captcha
§
Checks
for missing font file
Updated
on – Sep 19, 2013
§
Had
been reported of issues related to missing font file so i have updated the
controller function to detect the existence of font file. Dies with error on
missing font file. So don’t forget to upload attached font file. If
you wanted to use a different font upload it to webroot folder and
change settings['font'] parameter
Updated
on – April 12, 2013
§
Random captcha images are possible. Set
“theme”=>”random” in $settings variable of CaptchaComponent.php or in
Controller when loading captcha component.
§
Can’t Read? Reload is possible now. A working piece of
jQuery code is included in view fileadd.ctp. Be sure to include
jquery library, such ashttps://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js to
make Reloading of captcha working
How
to make it working
Download
attached zip file and extract. Copy all files placed in app folder to their corresponding
locations.
I
created “SignupsController” controller and Signup.php model for demonstration
purpose. Create a function similar to the following in your controller.
function
captcha() {
$this->autoRender = false;
$this->layout='ajax';
if(!isset($this->Captcha)) { //if Component
was not loaded through $components array()
$this->Captcha =
$this->Components->load('Captcha', array(
'width' => 150,
'height' => 50,
'theme' => 'random', //possible values :
default, random ; No value means 'default'
)); //load it
}
$this->Captcha->create();
}
Call
the captcha action from within your form tag in the view file, as below:
echo
$this->Session->flash();
$this->Captcha->render($captchaSettings);
echo
$this->Form->submit(__(' Submit ',true));
echo
$this->Form->end();
This
component includes a model file i.e. Model/Signup.php file to demonstrate the
use of model validation for captcha input by user. The validation works just
like any other custom model validation in CakePHP.

