2013-12-26 02:50:10 +00:00
|
|
|
<?php
|
|
|
|
namespace Helpers;
|
|
|
|
|
|
|
|
class Captcha extends \Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
|
|
|
public $captcha;
|
|
|
|
|
|
|
|
private $sessionName = "captcha";
|
2013-12-26 07:59:00 +00:00
|
|
|
private $imgDir = "images/captcha";
|
2013-12-26 02:50:10 +00:00
|
|
|
|
|
|
|
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,
|
2013-12-26 07:59:00 +00:00
|
|
|
'font' => '../data/fonts/ggbi.ttf',
|
|
|
|
'imgDir' => $this->imgDir,
|
|
|
|
'imgUrl' => '/images/captcha',
|
2013-12-26 02:50:10 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCaptcha(){
|
2013-12-26 07:59:00 +00:00
|
|
|
if(!is_dir($this->imgDir))
|
|
|
|
{
|
|
|
|
mkdir($this->imgDir);
|
|
|
|
}
|
|
|
|
|
2013-12-26 02:50:10 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|