I just had to build in a Captcha to a simple form on a small side, i thought of using the Zend_Captcha_ReCaptcha but also saw some disadvantages.
- Re Captcha is the most common used captcha, if anybody will build a universal spam bot, ReCaptcha might be first target to implement.
- Re Captcha depends on a service so if you implement it your site will also depend on this service
Implementing a Zend_Captcha_Image is pretty simple, it is not looking as nice as Re Captcha but also works.
here is the code.
$captchaImgDir =
'path/to/were/images/will/be/written';
$captcha =
'path/to/trueTypeFontFile.ttf';
$this->
addElement(new Zend_Form_Element_Captcha
('captcha',
array( 'captcha' =>
array( 'captcha' =>
'Image',
'height' =>
'40',
'font' =>
$captchaFont,
'imgDir' =>
$captchaImgDir,
'wordLen' =>
3,
'timeout' =>
300,
),
)));
The Zend_Captcha_Image has no standard view renderer, that is why we use the render function
<?=$this->formLabel('captcha', 'Security Code')?><br /> <?=$this->form->getElement('captcha')->render() ;?><br />
If there is time, i might implement a ultimate captcha solution, using Randomly choosen Zend_Captcha implementation this means a spambot would also have to implement different solutions.