控制器中:
$this->codeSession = new Zend_Session_Namespace('code'); //在默認構造函數裏實例化
$captcha = new Zend_Captcha_Image(array('font'=>'public/images/verdanaz.ttf', //字體文件路徑
'fontsize'=>12, //字號
'imgdir'=>'public/images/code/', //驗證碼圖片存放位置
'session'=>$this->codeSession, //驗證碼session值
'width'=>60, //圖片寬
'height'=>30, //圖片高
'wordlen'=>4 )); //字母數
$captcha->setDotNoiseLevel(5); //設置驗證碼背景圖片中的混淆點個數,默認爲100
$captcha->setGcFreq(3); //設置刪除生成的舊的驗證碼圖片的隨機機率
$captcha->generate(); //生成圖片
$this->view->ImgDir = $captcha->getImgDir();
$this->view->captchaId = $captcha->getId(); //獲取文件名,md5編碼
$this->codeSession->code=$captcha->getWord(); //獲取當前生成的驗證字符串
echo $this->codeSession->code;//得到的是驗證碼中的數字
$this->codeSession = new Zend_Session_Namespace('code'); //在默認構造函數裏實例化
$captcha = new Zend_Captcha_Image(array('font'=>'public/images/verdanaz.ttf', //字體文件路徑
'fontsize'=>12, //字號
'imgdir'=>'public/images/code/', //驗證碼圖片存放位置
'session'=>$this->codeSession, //驗證碼session值
'width'=>60, //圖片寬
'height'=>30, //圖片高
'wordlen'=>4 )); //字母數
$captcha->setDotNoiseLevel(5); //設置驗證碼背景圖片中的混淆點個數,默認爲100
$captcha->setGcFreq(3); //設置刪除生成的舊的驗證碼圖片的隨機機率
$captcha->generate(); //生成圖片
$this->view->ImgDir = $captcha->getImgDir();
$this->view->captchaId = $captcha->getId(); //獲取文件名,md5編碼
$this->codeSession->code=$captcha->getWord(); //獲取當前生成的驗證字符串
echo $this->codeSession->code;//得到的是驗證碼中的數字
視圖中:在需要引用驗證碼的地方加上
<img src="<?php echo $this->ImgDir .'/'.$this->captchaId "></img