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. 每日命令:(6)rmdir

    今天学习一下linux中命令: rmdir命令.rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删 ...

  2. Django-前后台的数据交互

    Django 从后台往前台传递数据时有多种方法可以实现. 最简单的后台是这样的: from django.shortcuts import render def main_page(request): ...

  3. circumferential averaged streamwise velocity in ParaView

    Goal: get a averaged axial velocity in a circular loop (dashed line in the following figure) Steps: ...

  4. 【Codeforces 979B】Treasure Hunt

    [链接] 我是链接,点我呀:) [题意] 每次你可以将一个字符变成一个不同于本身的字符. 每个人需要改变n次(且不能不改变) 设每个人的字符串中出现次数最多的字符出现的次数为cnt[0~2] 问你谁的 ...

  5. ceph rbd 入门

    1.一个现成的ceph cluster 参考之前写的ceph-deploy 部署ceph cluster 2.配置client与ceph cluster对接 在ceph cluster的管理节点上安装 ...

  6. python——正则表达式的理解

    概念:又称规则表达式,常用来检索.替换符合某个规则的文本. 理解:特殊字符--------->规则---------->过滤字符串 目的:1.匹配给定的字符串,2.从字符串中过滤出我们需要 ...

  7. SpringBoot @ConditionalOnBean、@ConditionalOnMissingBean注解源码分析与示例

    前言: Spring4推出了@Conditional注解,方便程序根据当前环境或者容器情况来动态注入bean,对@Conditional注解不熟悉的朋友可移步至 Spring @Conditional ...

  8. git巧妙命令行

    git cherry-pick c7081607cfd1bfa99b6e6c70c208e71fbd8767ae

  9. Choose and divide

    The binomial coefficient C(m, n) is defined as C(m, n) = m! (m − n)! n! Given four natural numbers p ...

  10. C. Painting Fence 分治

    memory limit per test 512 megabytes input standard input output standard output Bizon the Champion i ...