HTML_QuickForm_CAPTCHA
[ class tree: HTML_QuickForm_CAPTCHA ] [ index: HTML_QuickForm_CAPTCHA ] [ all elements ]

Source for file qfcaptcha_form_figlet.php

Documentation is available at qfcaptcha_form_figlet.php

  1. <?php
  2.  
  3. /**
  4.  * HTML_QuickForm_CAPTCHA "figlet" example - Form
  5.  *
  6.  * PHP versions 4 and 5
  7.  *
  8.  * @category   HTML
  9.  * @package    HTML_QuickForm_CAPTCHA
  10.  * @subpackage Examples
  11.  * @author     Philippe Jausions <Philippe.Jausions@11abacus.com>
  12.  * @copyright  2006-2008 by Philippe Jausions / 11abacus
  13.  * @license    http://www.opensource.org/licenses/bsd-license.php New BSD
  14.  * @version    CVS: $Id: qfcaptcha_form_figlet.php,v 1.1 2008/04/26 23:27:32 jausions Exp $
  15.  * @filesource
  16.  * @link       http://pear.php.net/package/HTML_QuickForm_CAPTCHA
  17.  */
  18.  
  19. /**
  20.  * Because the CAPTCHA element is serialized in the PHP session,
  21.  * you need to include the class declaration BEFORE the session starts.
  22.  * So BEWARE if you have php.ini session.auto_start enabled, you won't be
  23.  * able to use this element, unless you're also using PHP 5's __autoload()
  24.  * or php.ini's unserialize_callback_func setting
  25.  */
  26. require_once 'HTML/QuickForm.php';
  27. require_once 'HTML/QuickForm/CAPTCHA/Figlet.php';
  28.  
  29. /**
  30.  * A session is required to store the Text_CAPTCHA instance
  31.  */
  32.  
  33. // Figlet font is randomly picked from the list in "fonf_tile"
  34. $options = array('sessionVar' => basename(__FILE__'.php'),
  35.                  'options'    => array('font_file' => array(
  36.                                          '/usr/share/fonts/figlet/basic.flf',
  37.                                          '/usr/share/fonts/figlet/big.flf',
  38.                                          '/usr/share/fonts/figlet/nancyj.flf',
  39.                      )));
  40.  
  41. $form = new HTML_QuickForm('qfCaptcha');
  42.  
  43. $captcha_question =$form->addElement('CAPTCHA_Figlet''captcha_question',
  44.                                        'Can you read this?'$options);
  45. if (PEAR::isError($captcha_question)) {
  46.     echo $captcha_question->getMessage();
  47.     exit;
  48. }
  49.  
  50. $captcha_answer =$form->addElement('text''captcha''Enter the answer');
  51.  
  52. $form->addRule('captcha''Enter the letters you see',
  53.                'required'null'client');
  54.  
  55. $form->addRule('captcha''What you entered didn\'t match the letters',
  56.                'CAPTCHA'$captcha_question);
  57.  
  58. $form->addElement('submit''''Verify');
  59.  
  60. ?>
  61. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  62.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  63. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  64. <head>
  65. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  66. <title>HTML_QuickForm_CAPTCHA Figlet example</title>
  67. </head>
  68. <body>
  69. <h1>Figlet CAPTCHA HTML QuickForm</h1>
  70. <?php
  71. if ($form->validate()) {
  72.     // Prevent the re-use of the same CAPTCHA phrase for future submissions
  73.     // (If you do not destroy the CAPTCHA, someone could reuse the same
  74.     // answer over and over again...)
  75.     $captcha_question->destroy();
  76.  
  77.     echo '<p>Value matched</p>';
  78. else {
  79.     // Force a new CAPTCHA if the answer submitted was incorrect
  80.     // (this is not required, but it improves the effectiveness of the CAPTCHA
  81.     // by preventing brut force attack)
  82.     if ($form->getElementError('captcha')) {
  83.         $captcha_question->destroy();
  84.         $captcha_answer->setValue('');
  85.     }
  86.  
  87.     $form->display();
  88. }
  89.  
  90. ?>
  91. </body>
  92. </html>
  93. <?php
  94.  
  95. highlight_file(__FILE__);
  96.  
  97. ?>

Documentation generated on Mon, 11 Mar 2019 15:21:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.