1. Add the following code to the Sitecontroller:
PHP code
- /**
- * Declares class-based actions.
- */
- Public function Actions () {
- return Array (
- //CAPTCHA action renders the CAPTCHA image displayed on the contact page
- ' captcha ' = Array (
- ' class ' = ' ccaptchaaction ',
- ' backColor ' = 0xFFFFFF,
- ),
- //Page action renders "static" pages stored under ' protected/views/site/pages '
- //They can accessed Via:index.php?r=site/page&view=filename
- ' page ' = = Array (
- ' class ' = ' cviewaction ',
- ),
- );
- }
2, in the model/loginform.php
Add a property: public $verifyCode;
Added at the end of the Rules array: Array (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),
3, in the view, in the view/login.php need to add a verification code place to write:
<input id= ' Loginform_verifycode ' type= "text" Name= "Loginform[verifycode]" >
<?php $this->widget (' Ccaptcha ');?>
Below this can click the picture to change the verification code
<div><?php $this->widget (' Ccaptcha ', Array (' Showrefreshbutton ' =>false, ' clickableimage ' =>true, ' Imageoptions ' =>array (' alt ' = ' Click to change ', ' title ' = ' Click to change ', ' style ' = ' cursor:pointer '));?></div>
Add verification code in YII login