CakePHP 3.x Captcha, Google Recaptcha & Simple Match Challenge [All-in-one] Plugin
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
example/src
src
.gitignore
README.md
composer.json

README.md

CakePHP Captcha Plugin

Image captcha, Math captcha and Google-recaptcha support for CakePHP See CakePHP 1 & 2 version

Demo.

For questions queries please visit this link (coming soon)

Installation

Install via Composer

composer require inimist/cakephp-captcha:dev-master

and

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

OR

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

Implementation

  1. Load Captcha plugin.

    If you ran bin/cake plugin load Captcha -b -r above skip this step.

    Place Plugin::load('Captcha', ['routes' => true, 'autoload' => true]); in your application's Application.php or bootstrap.php file, whichever applicable.

  2. Load Capthca component

    Place $this->loadComponent('Captcha.Captcha'); in your controllerr's initialize function

    OR

    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!$

  3. Add Behavior to your Model/Table

    Place $this->addBehavior('Captcha.Captcha', ['field'=>'<fieldname>']) in your Model (Table class)

  4. Create an input field in your view's form as:

    echo $this->Captcha->create('<fieldname>');

  5. In your controller in which your form data is processed, place:

    $this->Users->setCaptcha('<fieldname>', $this->Captcha->getCode('<fieldname>'));

    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.

##More examples

###Custom settings:

echo $this->Form->create("Signups");
$custom1['width']=150;
$custom1['height']=50;
$custom1['theme']='default';
$this->Captcha->render($custom1);

###Multiple captchas:

//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.

Known Issues:

  1. 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.

  2. GD library and True Type Font (TTF) support extensions are enabled in PHP.

  3. 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.

Updates

2018-06-25 - Added ability to install via composer

Layout

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?