Download the PHP package jlorente/yii2-enhanced-captcha without Composer
On this page you can find all versions of the php package jlorente/yii2-enhanced-captcha. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jlorente/yii2-enhanced-captcha
More information about jlorente/yii2-enhanced-captcha
Files in jlorente/yii2-enhanced-captcha
Package yii2-enhanced-captcha
Short Description A Yii2 extension that enhances the captcha component with the functionality of being shown only on multiple requests from the same IP
License MIT
Homepage https://github.com/jlorente/yii2-enhanced-captcha
Informations about the package yii2-enhanced-captcha
Yii2 Enhanced Captcha
A Yii2 extension that enhances the captcha component with the functionality of being shown only on multiple requests from the same IP
Installation
Include the package as dependency under the bower.json file.
To install, either run
or add
to the section of your composer.json
file.
Usage
Loading the module
First at all you have to include the plugin as a module in your config file and bootstrap it.
You can include it by other ways. Anyway, the module id is irrelevant to use this Module, so you can establish the one you want. For more information about including modules see The Definitive Guide to Yii 2.0 - Modules.
The captcha Module uses a cache component to store the timestamp requests queue. By default it uses Apc Cache, but you can change this behavior setting the cache property in the module declaration.
For more information about supported cache storages and initialization of the component see the manual.
Other properties like the duration of the time period to check and the number of requests before the captcha will be shown can be established in the module configuration too.
By default the number of requests are 2 and the duration 120.
A controller action is provided along with the Module. This CaptchaAction can be configured in the module configuration params. See the manual to have a complete list of CaptchaAction configuration params.
Using the widget and the validator
Once the module is configured and loaded you can use the widget and validator with a Model.
Include the CaptchaValidator class as a validator for the captcha attribute.
And add the widget to the ActiveField of the captcha attribute in your view.
Now the captcha will be shown only if there are many requests from the same IP for the current model.
Further considerations
A request is counted when the CaptchaValidator is used, so if the validate method of the Model isn't called on form submit, the captcha will never be shown.
This module is an extension of the captcha functionality that comes with the Yii 2.0 framework to provide additional functionality, so if you want to see more options and configurations of the widget, validator and action please refer to the manual.
License
Copyright © 2015 José Lorente Martín [email protected]. Licensed under the MIT license. See LICENSE.txt for details.