在三江源子站中添加验证码助手helpers\Captcha

This commit is contained in:
Li Jianxuan 2013-12-26 02:54:05 +00:00
parent 543c8fcd2f
commit 9779a0bebe
1 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,52 @@
<?php
namespace Helpers;
class Captcha extends \Zend_Controller_Plugin_Abstract
{
public $captcha;
private $sessionName = "captcha";
function __construct($db = NULL)
{
$this->loadCaptcha();
}
public function loadCaptcha()
{
$this->captcha = new \Zend_Captcha_Image(array(
'captcha' => 'Image',
'wordLen' => 4,
'fontsize'=>16,
'width' => 100,
'height' => 38,
'dotNoiseLevel'=>2,
'lineNoiseLevel'=>1,
'timeout' => 300,
'font' => '../data/fonts/ggbi.ttf',
'imgDir' => 'vdimg/',
'imgUrl' => '/vdimg',
));
}
public function setCaptcha(){
$this->captcha->generate();
$_SESSION[$this->sessionName] = $this->captcha->getWord();
$url = $this->captcha->getImgUrl()
.$this->captcha->getId()
.$this->captcha->getSuffix();
return $url;
}
public function isValid($captchaword)
{
if($captchaword == $_SESSION[$this->sessionName])
{
return true;
}else{
return false;
}
}
}