![]() |
|
sfCryptoCaptchaPlugin - 0.1.1symfony captcha plugin |
|
This plugin generates a higly configurable captcha to block spam and robots. The script is based on the Cryptographp library but is actually a complete rewrite in PHP 5 and in OOP of the sfCryptographpPlugin that was available for symfony 1.0 on the trac wiki.
The plugin is easy to install, by using SVN or PEAR:
$ symfony plugin:install -s beta sfCryptoCaptchaPlugin
If this doesn't work, try the help option for plugin installation
$ symfony help plugin:install
$ svn co http://svn.symfony-project.com/plugins/sfCryptoCaptchaPlugin/trunk plugins/sfCryptoCaptchaPlugin
Activate the plugin in you applications settings.yml file:
all:
.settings:
enabled_modules: [default, sfCryptoCaptcha]
Then plublish the assets and clear the cache:
$ symfony plugin:publish-assets
$ symfony cc
This plugin can be easily configured with the app.yml file. All the options
are detailed in the comments of the original configuration file.
Some precisions thought:
When configuring the plugin, use the application
app.ymlfile to override the setting you want to change. Do not use the the pluginapp.ymlfile
Two helper functions are to be used in your template
<?php // in the head of your template, call the helper use_helper('sfCryptoCaptcha'); //the helper functions captcha_image(); captcha_reload_button(); ?> // in a table form it looks like this <tr> <th><?php echo $form['captcha']->renderLabel(); ?></th> <td> <?php echo $form['captcha']->renderError(); ?> <?php echo $form['captcha']->render(); ?> </td> <td><?php echo captcha_image(); echo captcha_reload_button(); ?></td> </tr>
The first helper displays the captcha image, the second one is the reload button (if the user can't read the picture and want to use another one).
To validate the entered captcha code in a form, use the sfValidatorSfCryptoCaptcha validator like so:
<?php //this is in your somePurposeForm.class.php file $this->setWidgets(array( // .. other fields .. 'captcha' => new sfWidgetFormInput(), // .. other fields .. )); $this->widgetSchema->setLabels(array( // .. other fields .. 'captcha' => 'Please copy the security code.', // .. other fields .. )); $this->setValidators(array( // .. other fields .. 'captcha' => new sfValidatorSfCryptoCaptcha(array('required' => true, 'trim' => true), array('wrong_captcha' => 'The code you copied is not valid.', 'required' => 'You did not copy any code. Please copy the code.')), // .. other fields .. )); $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
Here are some useful configuration details
The bg_img options can have many values:
Here's how it looks in the configuration app.yml file
--- bg_img: false #1 bg_img: '/plugins/sfCryptoCaptchaPlugin/media/bg/leaf_bg.png' #2 bg_img: '/plugins/sfCryptoCaptchaPlugin/media/bg' #3
When setting the letters for the captcha, be careful to exclude characters that look alike,
for example: o and 0 or B and 8 (when there is noise and funky fonts, there symbols quickly look alike).
You want to make it difficult for robots but not for your users.
For configurations needing paths (backgrounds, refresh button, fonts)
The error messages are internationalized if the i18n is turned on for symfony.
The images displayed will be in the /plugins/sfCryptoCaptchaPlugin/media/error/%SF_CULTURE%/...
directory and the extension used will be the same as the configured format. If there is no i18n
active, the three images will be taken from the /plugins/sfCryptoCaptchaPlugin/media/error/ directory.
The three needed images are:
unknown.xxx For unknown errorstoo_many.xxx For too many requests per session (maximum 1000 requests per session)refresh.xxx For too fast refreshesEach one of there images must be present in each culture folder or in the main error folder.
By default, a french and english version is provided. You can add as many languages and needed and customize the error images in any graphic editor(Gimp, Photoshop ...) as long as it is in jpeg, png or gif format [the same as the captcha format option].
There are no dependecies other than PHP >= 5.0.0
These are the things that need to be implemented/fixed:
For symfony 1.1 users only, you may have to comment or delete the whole lib/sfCryptoCaptchaPluginRouting.class.php file and add these routes manually for the plugin to work correctly:
---
captcha:
url: /captcha
param: { module: sfCryptoCaptcha , action: captcha }
captcha_refresh:
url: /captcha/:random
param: { module: sfCryptoCaptcha , action: captcha }
captcha_demo:
url: /captcha_demo
param: { module: sfCryptoCaptcha , action: captchaDemo }
If there is no image or no refresh button, check the following:
plugin:publish-assets command (under Windows, you may have to manually copy the sfCryptoCaptchaPlugin/web to the web/ directory)app.yml file)imagedestroy($this->image); line 220$this->clearBrush(); line 198If your captcha does not display correctly:
sfCryptoCaptchaPlugin (c) Terrance CAVENDISH
sfCryptographpPlugin (c) Leo CACHEUX
Cryptographp (c) Sylvain BRISON
http://www.mog-soft.org/symfony/download - sfCryptographpPlugin v1.0.0
http://www.symfony-project.com - symfony
http://www.cryptographp.com - Cryptographp
http://www.captcha.fr - Cryptographp