-
-
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();
- }
- function generatecaptcha() {
- $captcha = new zend_captcha_image();
- $captcha->settimeout('300')
- ->setwordlen('6')
- ->setheight('80')
- ->setfont('./images/font/micross.ttf')
- ->setimgdir('./images/code');
-
- $captcha->generate();
- return $captcha->getid();
- }
//validates captcha response
- 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 function indexAction() {
- $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';
- }
- }
- }
- }
- ?>
-
复制代码
|
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn