class TestController extends Lyw0301_Controller_Action { public function init() {parent::init(); $this->view->title = '测试' ; $this->view->baseUrl = $this->getFrontController()->getBaseUrl(); // $this->_helper->viewRenderer->setNoRender(); / /Zend_Layout::getMvcInstance()->disableLayout(); } functiongenerateCaptcha() { $captcha = new Zend_Captcha_Image(); $captcha->setTimeout('300') ->setWordLen(' 6') ->setHeight('80') ->setFont('./images/font/micross.ttf') ->setImgDir('./images/code'); $captcha ->生成(); return $captcha->getId(); } //キャプチャ応答を検証します function validateCaptcha($captcha) { $captchaId = $captcha['id']; $captchaInput = $captcha['input']; $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captchaId ); $captchaIterator = $captchaSession->getIterator(); Zend_Debug::dump($captchaIterator);exit; $captchaWord = $captchaIterator['word']; if($captchaWord) { if( $ captchaInput != $captchaWord ){ return false; } else { return true; } } else { return false; } } public functionindexAction() { $captchaId = $this->generateCaptcha (); $this->view->captchaId = $captchaId; if(isset($_POST['captcha'])) { $captcha = $_POST['captcha']; if( $this->validateCaptcha($captcha) ) { $this->view->message = 'yes'; } else { $this->view->message = 'no' ; } } } } ?> 复制代码