65 lines
1.2 KiB
PHP
65 lines
1.2 KiB
PHP
<?php
|
|
namespace Westdc\Helpers;
|
|
|
|
class Captcha
|
|
{
|
|
public $captcha;
|
|
|
|
private $sessionName = "captcha";
|
|
private $imgDir = "./public/images/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' => $this->imgDir,
|
|
'imgUrl' => '/images/captcha',
|
|
));
|
|
}
|
|
|
|
public function setCaptcha(){
|
|
if(!is_dir($this->imgDir))
|
|
{
|
|
mkdir($this->imgDir);
|
|
}
|
|
|
|
$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;
|
|
}
|
|
}
|
|
|
|
//资源回收
|
|
//删除目录中创建时间比超时时间久的
|
|
public function recycle()
|
|
{
|
|
|
|
}
|
|
|
|
} |