public function captcha2() { $path = BASEPATH . '../resources/captcha/' . (date('Y') . '/' . date('m') . '/' . date('d')); if (!file_exists($path)) { mkdir($path, 0777, TRUE); } $session = new Zend\Session\Container('ZEND_PARANGARI'); $session->offsetSet('text1', 'value1'); //$session->set $obj = new Zend\Captcha\Image(); $obj->setImgDir($path); $obj->setFont(BASEPATH . '../application/third_party/fonts/LesJoursHeureux.otf'); $obj->setFontSize(40); $obj->setWidth(250); $obj->setHeight(100); $obj->setDotNoiseLevel(40); $obj->setLineNoiseLevel(3); $obj->setWordlen(6); $obj->setSession($session); $string_captcha_ID = $obj->generate(); echo $string_captcha_ID . "<br/>"; echo $obj->getWord(); $obj->isValid($string_captcha_ID); Helper_Log::write($_SESSION); }
public function index01Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; //Tạo đối tượng chaptcha Image $captchaImg = new \Zend\Captcha\Image(); //Thiết lập đường dẫn đấn thư mục hình ảnh chứa captcha $captchaImg->setImgDir(CAPTCHA_PATH . "images"); //Thiết lập url cho hình ảnh captcha $captchaImg->setImgUrl(CAPTCHA_URL . "images"); //Thiết lập font $captchaImg->setFont(CAPTCHA_PATH . "fonts/Vharis.ttf"); //font-size $captchaImg->setFontSize(30); //length-char $captchaImg->setWordlen(5); //width-height cho captcha $captchaImg->setWidth(180); $captchaImg->setHeight(70); //set dấu chấm và đường chéo $captchaImg->setDotNoiseLevel(70); $captchaImg->setLineNoiseLevel(5); //Thiết lập ký tự xuất hiện AbstractWord::$VN = array("t"); AbstractWord::$CN = array("r"); //Phát sinh captcha $captchaImg->generate(); $imgUrl = $captchaImg->getImgUrl() . $captchaImg->getId() . $captchaImg->getSuffix(); return new ViewModel(array("imgUrl" => $imgUrl)); }