Add verification code in YII login

Source: Internet
Author: User

1. Add the following code to the Sitecontroller:

PHP code
  1. /**
  2. * Declares class-based actions.
  3. */
  4. Public function Actions () {
  5. return Array (
  6. //CAPTCHA action renders the CAPTCHA image displayed on the contact page
  7. ' captcha ' = Array (
  8. ' class ' = ' ccaptchaaction ',
  9. ' backColor ' = 0xFFFFFF,
  10. ),
  11. //Page action renders "static" pages stored under ' protected/views/site/pages '
  12. //They can accessed Via:index.php?r=site/page&view=filename
  13. ' page ' = = Array (
  14. ' class ' = ' cviewaction ',
  15. ),
  16. );
  17. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.