Based on reCaptcha API 2.0
You can clone the github repo and get the full codebase to build the distributive something you want.
-
1/ Download GitHub repo (dakiquang/yiiReCaptcha) and extract files into a destination folder(extensions folder/vendor folder or any folder in your structure)
-
2/ Sign up for an reCAPTCHA API keys on Google reCaptcha. and get the key/secret pair
-
3/ Configure this component in your configuration file (main.php file). The parameters siteKey and secret are required.
'components' => [
'reCaptcha' => [
'name' => 'reCaptcha',
'class' => '<path-to-destination-folder>\yiiReCaptcha\ReCaptcha',
'key' => '<your-key>',
'secret' => '<your-secret>',
],
...
4/ Add ReCaptchaValidator
in your model, for example:
public $verifyCode;
public function rules()
{
return array(
array('verifyCode', 'required'),
array('verifyCode', '<path-to-destination-folder>.yiiReCaptcha.ReCaptchaValidator'),
);
}
5/ Usage this widget in your view
<?php
$this->widget('<path-to-destination-folder>.yiiReCaptcha.ReCaptcha', array(
'model' => $model,
'attribute' => 'verifyCode',
));
?>
6/ Use for multiple domain: By default, the reCaptcha is restricted to the specified domain. Use the secure token to request a CAPTCHA challenge from any domain. Adding more attribute 'isSecureToken' => true
to setup for any domain:
<?php
$this->widget('<path-to-destination-folder>.yiiReCaptcha.ReCaptcha', array(
'model' => $model,
'attribute' => 'verifyCode',
'isSecureToken' => true,
));
?>
END.