验证码图片是不会自动删除的,所以生成的验证码图片所在文件夹体积会不断增加。怎么
办?
Image 类中是提供了方法的
$captcha
->setGcFreq(5) 。
具体使用方法看 API 吧
我希望自己设置
$id
,怎么办?
答案是在 Zend_Captche_Image 上再封装一层,然后重写 generate()方法
比如我重写了一个类:
代码如下:
class
Test_Captcha_Image
extends
Zend_Captcha_Image
{
protected
$_fid
= "";
public
function
generate()
{
$word
=
$this
->_generateWord();
$this
->_setWord(
$word
);
if
(
$this
->_fid) {
$id
=
$this
->_fid;
}
$this
->_generateImage(
$id
,
$this
->getWord());
if
(mt_rand(1,
$this
->getGcFreq()) == 1) {
$this
->_gc();
}
return
$id
;
}
public
function
setId(
$id
) {
$this
->_fid =
$id
;
return
$this
;
}
}
我希望我每个用户只有一个验证码,这个验证码的图片名称就是 userid.png
那么使用这个类的代码是这样的
代码如下:
$captcha
=
new
Test_Captcha_Image();