zoukankan      html  css  js  c++  java
  • yii登陆中添加验证码

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

    Php代码  收藏代码
    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> 

  • 相关阅读:
    linux服务 ssh
    详细教你两台电脑之间传文件
    openstack之keystone
    Token
    mybatis返回刚刚插入数据的自增长的id值
    事务配置在applicationContext.xml文件中不起作用,控制不了异常回滚
    SSM框架整合
    ssm框架的小总结
    spring_mvc入门项目的小总结
    tcp和udp的网络编程(发送消息及回复)
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4349439.html
Copyright © 2011-2022 走看看