PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
验证码类
<?php class Captcha extends CCaptchaAction { public function run() { if (isset($_GET[self::REFRESH_GET_VAR])) // AJAX request for regenerating code { $code = $this->getVerifyCode(true); echo CJSON::encode(array( 'hash1' => $this->generateValidationHash($code), 'hash2' => $this->generateValidationHash(strtolower($code)), // we add a random 'v' parameter so that FireFox can refresh the image // when src attribute of image tag is changed 'url' => $this->getController()->createUrl($this->getId(), array('v' => uniqid())), )); } else{ $this->renderImage($this->getVerifyCode(true)); //刷新页面时会调用这个,问题就出现在这,他调用 } Yii::app()->end(); } } controller调用 public function actions() { return array( // captcha action renders the CAPTCHA image displayed on the contact page 'captcha'=>array( 'class'=>'Captcha', 'maxLength'=>4, 'minLength'=>4, 'width' => 100 ), ); } html调用 <?php $this->widget('CCaptcha', array('showRefreshButton' => false, 'clickableImage' => true, 'imageOptions' => array('title' => '点击换图', 'style' => 'cursor:pointer;width: 110px; height: 35px;')));
转载请注明:谷谷点程序 » YII 验证码设置启用