yii 验证码的使用

在HappyController 中加入

  public function actions(){

        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            ‘captcha‘=>array(
                ‘class‘=>‘CCaptchaAction‘,
                ‘backColor‘=>0xFFFFFF,  //背景颜色
                ‘minLength‘=>4,  //最短为4位
                ‘maxLength‘=>4,   //是长为4位
                ‘transparent‘=>true,  //显示为透明
            ),
        );
    }

 public function actionIndex(){
    $this->layout = false;
    $this->render(‘index‘);
 }

在view视图中,添加如下代码,就可以得到验证码了。

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

yii 验证码的使用

时间: 2024-08-26 04:56:20

yii 验证码的使用的相关文章

Yii 验证码验证

控制器如下 LoginForm如下 视图如下 <div class="loginbody">            <span class="systemlogo"></span>             <div class="loginbox">                <ul>                    <?php $form = $this->beg

yii 验证码那点事儿

今天要使用yii验证码, 不过, 这个验证码是整站通用的, 也就是说, 有个表单的提交是使用ajax方式来提交, 整站, 不管在哪个地方, 都能点出来此窗口, 来提交信息 关于yii验证码, framework/web/widgets/captcha/CCaptcha.php里, 它源码里有这么一部分 >---protected function renderImage() >---{ >--->---if(!isset($this->imageOptions['id']))

yii 验证码 CCaptcha的总结(转)

今天用到yii的验证码 ccaptcha,经过在网上搜寻 找到以下例子: 1.在controller中加入代码 (1)启用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php public function actions()     {         return array(             // 启用验证码组件             'captcha'=>array(                 'class'=>'CCaptchaA

关于 yii 验证码显示, 但点击不能刷新的处理

先说说 render 与 renderPartial, 各位看官, 先别走, 我没跑题, 这个问题如果需要解决, 关键就在 render 与 renderPartial 的区别. renderPartial() 方法 public string renderPartial(string $view, array $data=NULL, boolean $return=false, boolean $processOutput=false) $view string name of the vie

yii 验证码的使用和验证过程

如果要实现这个过程的话,需要几个步骤 第一步就是controller的操作 在要操作的控制器中添加如下代码: public function actions(){ return array( // captcha action renders the CAPTCHA image displayed on the contact page 'captcha'=>array( 'class'=>'CCaptchaAction', 'backColor'=>0xFFFFFF, 'maxLeng

yii验证码Captcha使用以及为什么验证码不刷新问题

Web开发的过程中, 经常会用到验证码, 以防止机器人不断的提交数据, 造成网站的瘫痪. Yii里提供了一个验证码的插件, 就是Captcha. 第一步: 在项目中使用Captcha需要以下一些设置:在Controller里添加方法 actions public function actions () { return array ( 'captcha' => array ( 'class' => 'CCaptchaAction' , 'minLength' => 1 , 'maxLen

yii 验证码功能的实现

首先知晓我们在使用验证码的时候通常是和我们的表单小部件配合使用首先我们创建model层 新建一个php文件 名字叫做Verifycode.php 要在我们的model层 创建我们的验证码的验证规则,我这里简单的写两个规则 一个是 非空 另一个是验证码必须验证正确 规则写在我们的model的rules里 <?php/*** Created by PhpStorm.* User: jinlei* Date: 2017/2/13* Time: 13:57*/ namespace frontend\mo

mydetails

1.yii验证码多余的get a new code ,即使在main.php中配置了中文也是出现获取新图片,影响效果 需要把 <?php $this->widget('CCaptcha'); ?> 改成 <?php $this->widget('CCaptcha',array('showRefreshButton'=>false,'clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图','ti

Yii 2.0 使用验证码

Yii2.0 提供了验证码组件.调用起来比较方便.以登录页面添加验证码为例. 1. 模型中添加字段和验证规则. common\models\LoginForm 添加如下代码 public $captcha; //rules() 方法内添加 ['captcha', 'required'], ['captcha', 'captcha'], 2. 控制器中添加captcha的action backend\controllers\SiteController public function action