1、在SiteController中添加如下代码:

  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 be accessed via: index.php?r=site/page&view=FileName
  13. 'page' => array(
  14. 'class' => 'CViewAction',
  15. ),
  16. );
  17. }

2、在 Model/LoginForm.php中

添加一个属性: public $verifyCode;

在rules数组最后添加:array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),

3、在视图中,在view/login.php中需要添加验证码的地方写上:

<input id='LoginForm_verifyCode' type="text" name="LoginForm[verifyCode]" >

<?php $this->widget('CCaptcha'); ?>

// 下面这个可以点击图片进行换验证码

<div><?php $this->widget('CCaptcha',array('showRefreshButton'=>false,'clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图','title'=>'点击换图','style'=>'cursor:pointer'))); ?></div>

yii登陆中添加验证码的更多相关文章

  1. Yii Model中添加默认搜索条件

    在查询中增加条件 public function defaultScope() { return array( 'condition' => " is_deleted = 0" ...

  2. PHPCMS v9 自定义表单添加验证码验证

    1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=" ...

  3. PHPCMS v9 自定义表单添加验证码

    1.  在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=&quo ...

  4. [phpcms v9]自定义表单添加验证码验证功能

    修改  \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=" ...

  5. 【转】PHPCMS v9 自定义表单添加验证码验证

    1.  在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=&quo ...

  6. .Net 登陆的时候添加验证码

    一.ASPX 登陆界面验证码 1.登陆验证码图片和输入验证码框 <asp:TextBox ID="txtValiCode" runat="server" ...

  7. C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库

    C# DateTime的11种构造函数   别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...

  8. Sqlserver 中添加数据库登陆账号并授予数据库所有者权限

    Sqlserver 中添加数据库登陆账号并授予数据库所有者权限 USE master GO --通过sp_addlogin创建登录名 --DEMO:登陆账号 --123456:登陆密码 ' --切换数 ...

  9. yii添加验证码 和重复密码

    <?phpnamespace frontend\models; use common\models\User;use yii\base\Model;use Yii; /** * Signup f ...

随机推荐

  1. 19异常和file部分笔记

    19异常和file部分笔记-2018/09/041.异常  1.1 throwable()几个常见方法 * getMessage()获取异常信息,返回字符串 * toString()获取异常类名和异常 ...

  2. MySQL数据导入sql文件过程中出错

    错误类型: ERROR 1231 (42000): Variable 'time_zone' can't be set to the value of 'NULL' ERROR 1231 (42000 ...

  3. 59.关系型与document类型数据模型对比

    现假设有如下两个类: class Department(object): def __init__(self, dept_id, name, desc, employees=[]): self.dep ...

  4. Vue2 + Koa2 实现后台管理系统

    看了些 koa2 与 Vue2 的资料,模仿着做了一个基本的后台管理系统,包括增.删.改.查与图片上传. 工程目录: 由于 koa2 用到了 async await 语法,所以 node 的版本需要至 ...

  5. (六)python3 字符串常用方法

    字符串截取  >>>s = 'hello' >>>s[0:3] 'he' >>>s[:] #截取全部字符 'hello' 消除空格及特殊符号   ...

  6. codeforces round #394 (div. 2) A\B 题解

    开始啦~ 始まった T1 #include <stdio.h> int l,r,even,odd; void Jud(){ for(int i=1;i<=200;i++){ for( ...

  7. 恶补数论(二) Baby-Step-Giant-Step 大步小步求离散模对数

    知识概述 好吧,我承认这是我初三寒假就听过的知识,然而我现在早就高一了(又是寒假,只不过我已经在省选了...) 额,这是求离散模对数的一种算法 也就是求满足方程a^x≡b(mod p)的最小的x(其中 ...

  8. 3.6.5 空串与Null串

        空串""是长度为0的字符串.可以调用以下代码检查一个字符串是否为空:                 String s = "greeting";    ...

  9. print pdf bug & DOCTYPE

    print pdf bug & DOCTYPE OK with <!DOCTYPE html> <!DOCTYPE html> <html lang=" ...

  10. UVa - 12450 - SpaceRecon Tournament

    先上题目: Problem G: SpaceRecon Tournament SpaceRecon, the hottest game of 2011, is a real-time strategy ...