PHP Classes
elePHPant
Icontem

AMDev_Captcha: Generate form elements for CAPTCHA validation

Recommend this page to a friend!
  Info   Screenshots Screenshots   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2008-12-04 (7 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 1,112 All time: 3,249 This week: 1,044Up
Version License PHP version Categories
amdev_captcha 1.0.2GNU Lesser Genera...5HTML, PHP 5, Validation, Security
Description Author

This class generates a CAPTCHA validation images to embed in forms.

It is an enhanced version of hn_captcha package written originally by Nogajski. This version provides the following enhancements:

- Case-sensitive validation option
- Display an optional refresh link to generate a new picture with a different key using AJAX. Generating a new text this way does not count to the user attempts limit verification.
- Use of prefix for image file names
- Optional garbage collector to remove generated files after a given period
- Support for programmatic POST redirection to perform the CAPTCHA validation and then redirect the form data to any processing page
- Support for internationalization of messages
- Display the current CAPTCHA configuration
- Configurable passing an array of settings array when the object is initialized

Picture of Axel Pardemann
Name: Axel Pardemann <contact>
Classes: 1 package by
Country: Mexico Mexico
Age: 34
All time rank: 211021 in Mexico Mexico
Week rank: 1343 Up18 in Mexico Mexico Up

Details
This class generates a CAPTCHA (Completely Automated Public Turing to tell Computers from Humans Apart) image to embed in forms and validate them. After the test form is submitted a key entered by the user in a text field is compared by the class to determine whether it matches the text in the picture or not.

The class is based in the code of hn_captcha released also in this site by Horst Nogajski with the name hn_captcha.

The following enhancements were added:

- Display an optional refresh link to generate a new picture with a different key without counting to the user attempts limit verification using AJAX (xajax framework)
- Use of prefix for image filenames
- Includes the Garbage Collector with option to disable it
- Programatic POST redirection to perform the CAPTCHA validation and then redirect the form data to any processing page (not 100% stable)
- Messages for different languages are easier to change. It uses language files instead of changing code.
- Added a ConfigToString() function to display the current CAPTCHA configuration

All the configuration settings are passed to the class in an array when the object instance is initialized. For more details about the options read the readme.txt and the notes.txt


To run the example just place some ttf fonts in the captcha/fonts folder and it will work straight ahead.


The full configuration options list (this options are passwed in the init array to the contructor):

"DEBUG_ENABLED"				bool: If true then debugging is enabled.
"CAPTCHA_PATH"				string: Absolute or relative path to where the images will be saved. (Must be writable and must be in the same published web-tree as the script).
"CAPTCHA_PREFIX"			string: Prefix to be used for the image filenames.
"CAPTCHA_CLASS"				string: CSS class name for the displayed HTML tags.
"FONT_PATH"				string: Absolute or relative path to where the fonts collection is.
"FONT_COLLECTION"			mixed[array(strings)|string]: The font or array of fonts to be used. AUTO takes all fonts in FONT_PATH.
"CHAR_NUMBER"				integer: Length of the text string to be generated.
"CHAR_MIN_SIZE"				integer: Minimum size for a char in the captcha.
"CHAR_MAX_SIZE"				integer: Maximum size for a char in the captcha.
"CHAR_MAX_ROTATION"			integer: The maximum degrees a Char should be rotated. Set it to 30 means a random rotation between -30 and 30.
"CASE_SENSITIVE"			bool: If true the private key is case-sensitive.
"MAX_TRIES"				integer: Maximum input attempts before considering it an attack. Infinite attempts with MAX_TRIES=0.
"SESSION_INFO_LEN"			integer: The length of the session info string.
"SECRET_POS"				integer[1, SESSION_INFO_LEN]: Position in a 32 length string where the session tries are stored (must be less or equal to SESSION_INFO_LEN).
"SECRET_PHRASE"				string: A "secret" string to generate the md5 hash key.
"NOISE_ENABLED"				bool: If enabled captcha will be rendered with background noise, if not then just with a grid.
"NOISE_FACTOR"				integer: Background noise factor.
"LANGUAGE_FILE"				string: Absolute or relative path to the language file to be used for the text outputs.
"FORM_METHOD"				string[POST|GET]: The method the form is using to send the data.
"REFRESH_ENABLED"			bool: If enabled the user can requesta a captcha regeneration without modifying the try count.
"ONLY_MD5"				bool: If true it uses only the md5 function for encoding.
"WEB_SAFE_COLORS"			bool: If true the image will only use web safe colors.
"JPEG_QUALITY"				integer: Quality to be used for JPEG output image.
"XAJAX_INC_FILES"			mixed[array(strings)|string]: The relative paths to the include files for xajax.
"XAJAX_JS_PATH"				string: Absolute or relative path to the Xajax JS core file.
"XAJAX_DEBUG_ENABLED"			bool: If true then Xajax debug is enabled.
"GC_ENABLED"				bool: If true the GC is enabled.
"GC_IDLE_COUNT"				integer: Number of captchas to generate before calling GC.
"GC_CAPTCHA_PERIOD"			integer: Captcha alive period in seconds before GC collects it.
Screenshots  
  • screenshot.jpg
  Files folder image Files  
File Role Description
Files folder imagecaptcha (2 directories)
Plain text file AMDev.Tools.Captcha.php Class AMDev_Captcha class source code
Plain text file finish.php Aux. Results display
Plain text file index.php Example Form with embeded CAPTCHA
Plain text file notes.txt Doc. Notes
Plain text file readme.txt Doc. Readme
Plain text file redirect.php Aux. Processing form data page
Plain text file styles.css Data CSS Styles for the CAPTCHA

  Files folder image Files  /  captcha  
File Role Description
Files folder imagelanguages (4 files)
Files folder imagexajax (3 files)

  Files folder image Files  /  captcha  /  languages  
File Role Description
  Plain text file de.lng Data German language file. Thanks to Matthias Brunner
  Plain text file en.lng Data English language for CAPTCHA messages
  Plain text file es.lng Data Spanish language for CAPTCHA messages
  Plain text file fr.lng Data French language file. Thanks to JMM

  Files folder image Files  /  captcha  /  xajax  
File Role Description
  Plain text file xajaxAIO.inc.php Class xajax PHP framework compiled
  Plain text file xajax_core.js Data xajax JS core
  Plain text file xajax_debug.js Data xajax JS debug file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,112
This week:0
All time:3,249
This week:1,044Up