CakePHP Captcha Plugin
Image captcha, Math captcha and Google-recaptcha support for CakePHP See CakePHP 1 & 2 version
For questions queries please visit this link (coming soon)
Install via Composer
composer require inimist/cakephp-captcha:dev-master
bin/cake plugin load Captcha -b -r
Install via Download
Download and copy all files to your app's /plugins/captcha folder of your cakephp 3 application
In the command line, cd command to your app's plugins folder and run git clone
$ cd myapp/plugins $ git clone https://github.com/inimist/cakephp3-captcha.git captcha
Load Captcha plugin.
If you ran
bin/cake plugin load Captcha -b -rabove skip this step.
Plugin::load('Captcha', ['routes' => true, 'autoload' => true]);in your application's Application.php or bootstrap.php file, whichever applicable.
Load Capthca component
$this->loadComponent('Captcha.Captcha');in your controllerr's initialize function
Load Captcha component on the fly, in the particular controller action function. For example in the signup() action:
$$this->loadComponent('Captcha.Captcha'); //or load on the fly!$
Add Behavior to your Model/Table
$this->addBehavior('Captcha.Captcha', ['field'=>'<fieldname>'])in your Model (Table class)
Create an input field in your view's form as:
In your controller in which your form data is processed, place:
just before patching entity. For example:
$this->Users->setCaptcha('securitycode', $this->Captcha->getCode('securitycode')); $user = $this->Users->patchEntity($user, $this->request->data);
See example/src folder for a working example.
echo $this->Form->create("Signups"); $custom1['width']=150; $custom1['height']=50; $custom1['theme']='default'; $this->Captcha->render($custom1);
//form 1 echo $this->Form->create("Signups"); $custom1['width']=150; $custom1['height']=50; $this->Captcha->render($custom1); //form 2, A math captcha, anywhere on the page echo $this->Form->create("Users"); $custom2['type']='math'; $this->Captcha->render($custom2);
Settings that can be set in your view file:
- field: field name.
- type: image or math. If set to 'math' all following settings will be obsolete
- width: width of image captcha
- height: height of image captcha
- theme: theme/difficulty image captcha
- length: number of characters in image captcha
- angle: angle of rotation for characters in image captcha
Additional settings that can be set.
- fontAdjustment: Responsible for the font size relational to Captcha Image Size
- reload_txt: The phrase which appears as a Captcha Reload link
- clabel: Label for Image Captcha Value input field
- mlabel: Label for Math Captcha Value input field
That should be it.
Headers already sent issue. The component uses php's
header()function to send or generate captcha image as raw HTML output. Make sure there is no output generated before the create() function in your component. It is common error to have spaces, tags or empty space in your files which would cause rending no image in the captcha.
GD library and True Type Font (TTF) support extensions are enabled in PHP.
This captcha script uses three font faces, anonymous, droidsans and ubuntu to generate fonts in the captcha images. These font faces are placed in the captcha/src/Lib/Fonts of this download. I have seen that, sometimes, these font files get corrupted during downloads. If you see font not found error in your error logs and captcha are failed to generate, try downloading these font faces from their respective sources and replace them in the mentioned folder. You can also use different font families by placing them Fonts folder and referencing them in the CaptchaComponent.php component file.
2018-06-25 - Added ability to install via composer
Three basic options, image captcha, math captcha and google-recaptcha
Check older version for more options here.. These should be valid in this version as well.
Looking for a CakePHP Developer?
- I like to help with building websites, CRMs, SaaS applications and custom solutions using CakePHP & Wordpress. Contact me.
- Upwork: https://www.upwork.com/freelancers/~01ea3d34e0a88133b3