gpt4 book ai didi

php - Yii 验证码没有改变

转载 作者:行者123 更新时间:2023-12-04 05:13:40 26 4
gpt4 key购买 nike

我的验证码没有变化,总是出现同一个词,除非点击 Reload Captcha按钮。为什么testLimit工作不正常?

Controller .php

public $attempts = 5; // allowed 5 attempts
public $counter;

public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xf5f5f5,
'testLimit'=>1,
);
}

private function captchaRequired()
{
return Yii::app()->session->itemAt('captchaRequired') >= $this->attempts;
}

public function actionLogin()
{
if (!Yii::app()->user->isGuest) $this->redirect(array('users/update'));

$model = $this->captchaRequired()? new LoginForm('captchaRequired') : new LoginForm;

// collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login()) {
$this->redirect(array('users/update'));
} else {
$this->counter = Yii::app()->session->itemAt('captchaRequired') + 1;
Yii::app()->session->add('captchaRequired',$this->counter);
}
}
// display the login form
$this->render('login',array('model'=>$model));
}

查看.php
<?php if($model->scenario == 'captchaRequired'): ?>
<br>
<legend><?php echo CHtml::activeLabelEx($model,'verifyCode'); ?></legend>
<div class="control-group">
<div class="controls">
<?php $this->widget('CCaptcha'); ?>
<?php echo CHtml::activeTextField($model,'verifyCode'); ?>
</div>
</div>
<?php endif; ?>

最佳答案

testLimit是验证码提交的数量,用户可以在生成的散列更改之前尝试。用于避免拼写错误。

验证代码存储在 session ( http://www.yiiframework.com/doc/api/1.1/CCaptchaAction#getVerifyCode-detail )中,因此默认代码只能更改以下两种方式之一:使用 testLimit 提交表单代码不正确或用户手动更新的次数。

所以你可以扩展 CCaptchaAction 类来实现你想要的,例如力集$regenerate变量为真。

关于php - Yii 验证码没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14567482/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com