Hi all,

I have extended Zend_Captcha_Word and am rendering a custom captcha by
overriding generate()

Everything is working fine and just like Zend_Captcha_Image I am writing the
captcha png to ./images/captcha/

This will work fine in a single server environment but in a multi server
environment what happens if the image request goes to a server without the
generated image?

So I created a ImagesController and a captchaAction() that will get hit by a
second server and generate / render the image if necessary.

The problem with this is that I created a method as follows

public function regenerateImage($id)
{
        $this->_setId($id);
        $this->_generateImage($id, $this->getWord());
}

getWord() in turn calls getSession() which reads the session namespace for
the corresponding captcha id.. Which in turn decreases the hop counter and
the namespace gets deleted.

I modified the method as follows

public function regenerateImage($id)
{
        if (isset($_SESSION['__ZF']['Zend_Form_Captcha_' . $id]['ENNH']))
                $_SESSION['__ZF']['Zend_Form_Captcha_' . $id]['ENNH']++;

        $this->_setId($id);
        $this->_generateImage($id, $this->getWord());
}

This is the only way I figure I can get the namespace to not be deleted. It
seems a bit hackish but I can live with it.

Does anyone have any better ideas? I thought I could extend
Zend_Session_Namespace.. Or maybe it would be nice to support ignoring the
expiration logic when constructing a namespace (although this may be a very
specific use case).

Thanks,

Dylan

Reply via email to