cvs: pear /HTML_QuickForm_CAPTCHA/docs/examples qfcaptcha_form_equation.php qfcaptcha_form_figlet.php qfcaptcha_form_image.php qfcaptcha_form_random.php qfcaptcha_form_word.php qfcaptcha_image.php
[email protected] ("Philippe Jausions")
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvsjausions1209252452@cvsserver> |
jausions Sat Apr 26 23:27:32 2008 UTC
Added files:
/pear/HTML_QuickForm_CAPTCHA/docs/examples
qfcaptcha_form_equation.php
qfcaptcha_form_figlet.php
qfcaptcha_form_image.php
qfcaptcha_form_random.php
qfcaptcha_form_word.php
qfcaptcha_image.php
Log:
Finally checking in the code of HTML_QuickForm_CAPTCHA 0.3.0
jausions-20080426232732.txt
(text/plain, 19.6 KB)
http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_equation.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_equation.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_equation.php <?php /** * HTML_QuickForm_CAPTCHA "Equation" example - Form * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_form_equation.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA */ /** * Because the CAPTCHA element is serialized in the PHP session, * you need to include the class declaration BEFORE the session starts. * So BEWARE if you have php.ini session.auto_start enabled, you won't be * able to use this element, unless you're also using PHP 5's __autoload() * or php.ini's unserialize_callback_func setting */ require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Equation.php'; /** * A session is required to store the Text_CAPTCHA instance */ session_start(); $options = array('sessionVar' => basename(__FILE__, '.php')); $form = new HTML_QuickForm('qfCaptcha'); $captcha_question =& $form->addElement('CAPTCHA_Equation', 'captcha_question', 'Can you resolve this?', $options); if (PEAR::isError($captcha_question)) { echo $captcha_question->getMessage(); exit; } $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'Enter the answer to the equation', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match the equation', 'CAPTCHA', $captcha_question); $form->addElement('submit', '', 'Verify'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm_CAPTCHA Equation example</title> </head> <body> <h1>Equation CAPTCHA HTML QuickForm</h1> <?php if ($form->validate()) { // Prevent the re-use of the same CAPTCHA phrase for future submissions // (If you do not destroy the CAPTCHA, someone could reuse the same // answer over and over again...) $captcha_question->destroy(); // Don't need to see CAPTCHA related elements $form->removeElement('captcha_question'); $form->removeElement('captcha'); $form->freeze(); echo '<p>Value matched</p>'; } else { // Force a new CAPTCHA if the answer submitted was incorrect // (this is not required, but it improves the effectiveness of the CAPTCHA // by preventing brut force attack) if ($form->getElementError('captcha')) { $captcha_question->destroy(); $captcha_answer->setValue(''); } $form->display(); } ?> </body> </html> <?php highlight_file(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_figlet.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_figlet.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_figlet.php <?php /** * HTML_QuickForm_CAPTCHA "figlet" example - Form * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_form_figlet.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA */ /** * Because the CAPTCHA element is serialized in the PHP session, * you need to include the class declaration BEFORE the session starts. * So BEWARE if you have php.ini session.auto_start enabled, you won't be * able to use this element, unless you're also using PHP 5's __autoload() * or php.ini's unserialize_callback_func setting */ require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Figlet.php'; /** * A session is required to store the Text_CAPTCHA instance */ session_start(); // Figlet font is randomly picked from the list in "fonf_tile" $options = array('sessionVar' => basename(__FILE__, '.php'), 'options' => array('font_file' => array( '/usr/share/fonts/figlet/basic.flf', '/usr/share/fonts/figlet/big.flf', '/usr/share/fonts/figlet/nancyj.flf', ))); $form = new HTML_QuickForm('qfCaptcha'); $captcha_question =& $form->addElement('CAPTCHA_Figlet', 'captcha_question', 'Can you read this?', $options); if (PEAR::isError($captcha_question)) { echo $captcha_question->getMessage(); exit; } $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'Enter the letters you see', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match the letters', 'CAPTCHA', $captcha_question); $form->addElement('submit', '', 'Verify'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm_CAPTCHA Figlet example</title> </head> <body> <h1>Figlet CAPTCHA HTML QuickForm</h1> <?php if ($form->validate()) { // Prevent the re-use of the same CAPTCHA phrase for future submissions // (If you do not destroy the CAPTCHA, someone could reuse the same // answer over and over again...) $captcha_question->destroy(); echo '<p>Value matched</p>'; } else { // Force a new CAPTCHA if the answer submitted was incorrect // (this is not required, but it improves the effectiveness of the CAPTCHA // by preventing brut force attack) if ($form->getElementError('captcha')) { $captcha_question->destroy(); $captcha_answer->setValue(''); } $form->display(); } ?> </body> </html> <?php highlight_file(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_image.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_image.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_image.php <?php /** * HTML_QuickForm_CAPTCHA Image example - Form * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_form_image.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA * @see qfcaptcha_image.php */ /** * Because the CAPTCHA element is serialized in the PHP session, * you need to include the class declaration BEFORE the session starts. * So BEWARE if you have php.ini session.auto_start enabled, you won't be * able to use this element, unless you're also using PHP 5's __autoload() * or php.ini's unserialize_callback_func setting */ require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Image.php'; /** * A session is required to store the Text_CAPTCHA instance */ session_start(); $form = new HTML_QuickForm('qfCaptcha'); /** * - Default image size is 200 x 80 pixels * - Default session variable to store phrase in is _HTML_QuickForm_CAPTCHA * - Default font info is as listed below * It is imperative to have a correct font path and file! * * 'callback' is the URL to the script that will generate the actual image * Here "qfcaptcha_image.php" refer to the other example file (also in this * package.) */ $options = array( 'width' => 250, 'height' => 90, 'callback' => 'qfcaptcha_image.php?var='.basename(__FILE__, '.php'), 'sessionVar' => basename(__FILE__, '.php'), 'imageOptions' => array( 'font_size' => 20, 'font_path' => '/usr/share/fonts/truetype/', 'font_file' => 'cour.ttf') ); // Minimum options using all defaults (including defaults for Image_Text): //$options = array('callback' => 'qfcaptcha_image.php'); $captcha_question =& $form->addElement('CAPTCHA_Image', 'captcha_question', 'Verification', $options); if (PEAR::isError($captcha_question)) { echo $captcha_question->getMessage(); exit; } $form->addElement('static', null, null, 'Click on the image for a new one'); $form->addElement('text', 'captcha', 'Enter the letters you see'); $form->addRule('captcha', 'Enter the characters you read in the image', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match the picture', 'CAPTCHA', $captcha_question); $form->addElement('submit', '', 'Verify'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm_CAPTCHA Image example</title> </head> <body> <h1>Image CAPTCHA HTML QuickForm</h1> <?php if ($form->validate()) { // Prevent re-use of the same CAPTCHA phrase $captcha_question->destroy(); echo '<p>Value matched</p>'; } else { $form->display(); } ?> <p><a href="qfcaptcha_image.phps">PHP file source for CAPTCHA image code</a></p> </body> </html> <?php highlight_file(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_random.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_random.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_random.php <?php /** * HTML_QuickForm_CAPTCHA mix example - Form * * In this example, we'll pick the type of CAPTCHA loaded at runtime. So, if * the answer doesn't match the first time, the user may be prompted for a * different type of CAPTCHA on the next try. * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_form_random.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA * @see qfcaptcha_image.php */ /** * Because the CAPTCHA elements are serialized in the PHP session, * you need to include the class declarations BEFORE the session starts. * So BEWARE if you have php.ini session.auto_start enabled, you won't be * able to use this element, unless you're also using PHP 5's __autoload() * or php.ini's unserialize_callback_func setting */ require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Equation.php'; require_once 'HTML/QuickForm/CAPTCHA/Figlet.php'; require_once 'HTML/QuickForm/CAPTCHA/Image.php'; require_once 'HTML/QuickForm/CAPTCHA/Word.php'; /** * A session is required to store the Text_CAPTCHA instance */ session_start(); // Options are mixed between the different CAPTCHA drivers // (see the other examples for more details) $options = array('sessionVar' => basename(__FILE__, '.php'), 'options' => array('font_file' => array( '/usr/share/fonts/figlet/basic.flf', '/usr/share/fonts/figlet/big.flf', '/usr/share/fonts/figlet/nancyj.flf', )), 'width' => 250, 'height' => 90, 'callback' => 'qfcaptcha_image.php?var=' .basename(__FILE__, '.php'), 'imageOptions' => array( 'font_size' => 20, 'font_path' => '/usr/share/fonts/truetype/', 'font_file' => 'cour.ttf'), ); $form = new HTML_QuickForm('qfCaptcha'); // Pick a random CAPTCHA driver $drivers = array('CAPTCHA_Word', 'CAPTCHA_Image', 'CAPTCHA_Equation', 'CAPTCHA_Figlet', ); $captcha_type = $drivers[array_rand($drivers)]; // Create the CAPTCHA element: $captcha_question =& $form->addElement($captcha_type, 'captcha_question', 'How do you understand this?', $options); if (PEAR::isError($captcha_question)) { echo $captcha_type . ' :: ' . $captcha_question->getMessage(); exit; } $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'Enter your answer', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match. Try again.', 'CAPTCHA', $captcha_question); $form->addElement('checkbox', 'blocker', 'Validate Form?', 'Uncheck this box to fail form validation (beside CAPTCHA)'); $form->addRule('blocker', 'Form failed validation', 'required'); $form->setDefaults(array('blocker' => 1)); $form->addElement('submit', '', 'Verify'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm_CAPTCHA random example</title> </head> <body> <h1>Random CAPTCHA Type HTML QuickForm</h1> <?php if ($form->validate()) { // Prevent the re-use of the same CAPTCHA phrase for future submissions // (If you do not destroy the CAPTCHA, someone could reuse the same // answer over and over again...) $captcha_question->destroy(); // Don't need to see CAPTCHA related elements $form->removeElement('captcha_question'); $form->removeElement('captcha'); $form->freeze(); echo '<p>Value matched!</p>'; $form->display(); } else { // Since the CAPTCHA created within this call might be of a different type // from one created from a previous call (i.e. page refresh, or form // didn't validate) we need to scrap the old instance (of Text_CAPTCHA). // That's what the destroy() method does. // Downside is if the CAPTCHA was answered properly but the form // otherwise didn't pass validation, the user will have to reenter a new // answer to the CAPTCHA... $captcha_question->destroy(); $captcha_answer->setValue(''); $form->display(); } ?> </body> </html> <?php highlight_file(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_word.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_word.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_form_word.php <?php /** * HTML_QuickForm_CAPTCHA "Word" example - Form * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_form_word.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA */ /** * Because the CAPTCHA element is serialized in the PHP session, * you need to include the class declaration BEFORE the session starts. * So BEWARE if you have php.ini session.auto_start enabled, you won't be * able to use this element, unless you're also using PHP 5's __autoload() * or php.ini's unserialize_callback_func setting */ require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/CAPTCHA/Word.php'; /** * A session is required to store the Text_CAPTCHA instance */ session_start(); $options = array('sessionVar' => basename(__FILE__, '.php')); $form = new HTML_QuickForm('qfCaptcha'); $captcha_question =& $form->addElement('CAPTCHA_Word', 'captcha_question', 'Can you read this?', $options); if (PEAR::isError($captcha_question)) { echo $captcha_question->getMessage(); exit; } $captcha_answer =& $form->addElement('text', 'captcha', 'Enter the answer'); $form->addRule('captcha', 'Enter the answer to the question', 'required', null, 'client'); $form->addRule('captcha', 'What you entered didn\'t match the question', 'CAPTCHA', $captcha_question); $form->addElement('submit', '', 'Verify'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm_CAPTCHA "Spelled-Out Number Words" example</title> </head> <body> <h1>Spelled-Out Number Words CAPTCHA HTML QuickForm</h1> <?php if ($form->validate()) { // Prevent the re-use of the same CAPTCHA phrase for future submissions // (If you do not destroy the CAPTCHA, someone could reuse the same // answer over and over again...) $captcha_question->destroy(); echo '<p>Value matched</p>'; } else { // Force a new CAPTCHA if the answer submitted was incorrect // (this is not required, but it improves the effectiveness of the CAPTCHA // by preventing brut force attack) if ($form->getElementError('captcha')) { $captcha_question->destroy(); $captcha_answer->setValue(''); } $form->display(); } ?> </body> </html> <?php highlight_file(__FILE__); ?> http://cvs.php.net/viewvc.cgi/pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_image.php?view=markup&rev=1.1 Index: pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_image.php +++ pear/HTML_QuickForm_CAPTCHA/docs/examples/qfcaptcha_image.php <?php /** * HTML_QuickForm_CAPTCHA example - Image generator * * PHP versions 4 and 5 * * @category HTML * @package HTML_QuickForm_CAPTCHA * @subpackage Examples * @author Philippe Jausions <[email protected]> * @copyright 2006-2008 by Philippe Jausions / 11abacus * @license http://www.opensource.org/licenses/bsd-license.php New BSD * @version CVS: $Id: qfcaptcha_image.php,v 1.1 2008/04/26 23:27:32 jausions Exp $ * @filesource * @link http://pear.php.net/package/HTML_QuickForm_CAPTCHA * @see qfcaptcha_form_image.php * @see qfcaptcha_form_random.php */ // Require the class before opening the session // so the instance unserialize properly require_once 'Text/CAPTCHA.php'; require_once 'Text/CAPTCHA/Driver/Image.php'; session_start(); header('Content-Type: image/jpeg'); $sessionVar = (empty($_REQUEST['var'])) ? '_HTML_QuickForm_CAPTCHA' : $_REQUEST['var']; // Force a new CAPTCHA for each one displayed $_SESSION[$sessionVar]->setPhrase(); echo $_SESSION[$sessionVar]->getCAPTCHAAsJPEG(); ?>