验证码功能封装!

This commit is contained in:
Li Heng 2013-12-26 09:08:35 +00:00
parent ba94ea7b7f
commit 985272db6a
2 changed files with 11 additions and 7 deletions

View File

@ -6,6 +6,7 @@ class Captcha extends \Zend_Controller_Plugin_Abstract
public $captcha; public $captcha;
private $sessionName = "captcha"; private $sessionName = "captcha";
private $imgDir = "images/captcha";
function __construct($db = NULL) function __construct($db = NULL)
{ {
@ -16,7 +17,7 @@ class Captcha extends \Zend_Controller_Plugin_Abstract
{ {
$this->captcha = new \Zend_Captcha_Image(array( $this->captcha = new \Zend_Captcha_Image(array(
'captcha' => 'Image', 'captcha' => 'Image',
'wordLen' => 4, 'wordLen' => 6,
'fontsize'=>16, 'fontsize'=>16,
'width' => 100, 'width' => 100,
'height' => 38, 'height' => 38,
@ -24,12 +25,17 @@ class Captcha extends \Zend_Controller_Plugin_Abstract
'lineNoiseLevel'=>1, 'lineNoiseLevel'=>1,
'timeout' => 300, 'timeout' => 300,
'font' => '../data/fonts/ggbi.ttf', 'font' => '../data/fonts/ggbi.ttf',
'imgDir' => 'vdimg/', 'imgDir' => $this->imgDir,
'imgUrl' => '/vdimg', 'imgUrl' => '/images/captcha',
)); ));
} }
public function setCaptcha(){ public function setCaptcha(){
if(!is_dir($this->imgDir))
{
mkdir($this->imgDir);
}
$this->captcha->generate(); $this->captcha->generate();
$_SESSION[$this->sessionName] = $this->captcha->getWord(); $_SESSION[$this->sessionName] = $this->captcha->getWord();
$url = $this->captcha->getImgUrl() $url = $this->captcha->getImgUrl()

View File

@ -26,10 +26,8 @@ class Local extends \Zend_Controller_Plugin_Abstract
$this->db = $db; $this->db = $db;
} }
$this->config = \Zend_Registry::get('config'); $this->config = \Zend_Registry::get('6config');
# $Listener = new ReferenceListener();
# @$this->events()->attachAggregate($Listener);
$this->table = new \Helpers\Table(); $this->table = new \Helpers\Table();
} }