public function index03Action() { $captchaImg = new \ZendVN\Captcha\Image(70, 250, array("wordlen" => "5")); $imgUrl = $captchaImg->getImgUrl() . $captchaImg->getId() . $captchaImg->getSuffix(); if ($this->request->isPost()) { $captcha_user = $this->request->getPost("captcha_user"); $captcha_hidden = $this->request->getPost("captcha_id"); $validate = new \ZendVN\Validator\Captcha($captcha_hidden); if ($validate->isValid($captcha_user)) { echo "OK"; } else { echo "<pre style='font-weight:bold'>"; print_r($validate->getMessages()); echo "</pre>"; } $captchaImg->removeOldCaptcha($captcha_hidden); } return new ViewModel(array("imgUrl" => $imgUrl, "captcha_id" => $captchaImg->getId())); }
public function captchaAction() { $captchaObj = new \ZendVN\Captcha\Image(300, 50, array('wordlen' => 5, 'suffix' => '.jpg')); if ($this->getRequest()->isPost()) { $txtCaptcha = $this->getRequest()->getPost('captcha_code'); $captchaHidden = $this->getRequest()->getPost('captcha_hidden'); $validator = new \ZendVN\Validator\Captcha($captchaHidden); if ($validator->isValid($txtCaptcha)) { echo 'ok'; } else { $message = $validator->getMessages(); echo $message['captchaNotEqual']; } $captchaObj->remove($captchaHidden); } return array('imageUrl' => $captchaObj->getImgUrl() . $captchaObj->getId() . $captchaObj->getSuffix(), 'captchaID' => $captchaObj->getId()); }