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

Source for file qfcaptcha_form_image.php

Documentation is available at qfcaptcha_form_image.php

  1. <?php
  2.  
  3. /**
  4.  * HTML_QuickForm_CAPTCHA Image 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_image.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.  * @see        qfcaptcha_image.php
  18.  */
  19.  
  20. /**
  21.  * Because the CAPTCHA element is serialized in the PHP session,
  22.  * you need to include the class declaration BEFORE the session starts.
  23.  * So BEWARE if you have php.ini session.auto_start enabled, you won't be
  24.  * able to use this element, unless you're also using PHP 5's __autoload()
  25.  * or php.ini's unserialize_callback_func setting
  26.  */
  27. require_once 'HTML/QuickForm.php';
  28. require_once 'HTML/QuickForm/CAPTCHA/Image.php';
  29.  
  30. /**
  31.  * A session is required to store the Text_CAPTCHA instance
  32.  */
  33.  
  34. $form = new HTML_QuickForm('qfCaptcha');
  35.  
  36. /**
  37.  * - Default image size is 200 x 80 pixels
  38.  * - Default session variable to store phrase in is _HTML_QuickForm_CAPTCHA
  39.  * - Default font info is as listed below
  40.  *   It is imperative to have a correct font path and file!
  41.  *
  42.  * 'callback' is the URL to the script that will generate the actual image
  43.  * Here "qfcaptcha_image.php" refer to the other example file (also in this
  44.  * package.)
  45.  */
  46. $options = array(
  47.     'width'        => 250,
  48.     'height'       => 90,
  49.     'callback'     => 'qfcaptcha_image.php?var='.basename(__FILE__'.php'),
  50.     'sessionVar'   => basename(__FILE__'.php'),
  51.     'imageOptions' => array(
  52.         'font_size' => 20,
  53.         'font_path' => '/usr/share/fonts/truetype/',
  54.         'font_file' => 'cour.ttf')
  55.     );
  56.  
  57. // Minimum options using all defaults (including defaults for Image_Text):
  58. //$options = array('callback' => 'qfcaptcha_image.php');
  59.  
  60. $captcha_question =$form->addElement('CAPTCHA_Image''captcha_question',
  61.                                        'Verification'$options);
  62. if (PEAR::isError($captcha_question)) {
  63.     echo $captcha_question->getMessage();
  64.     exit;
  65. }
  66.  
  67. $form->addElement('static'nullnull'Click on the image for a new one');
  68.  
  69. $form->addElement('text''captcha''Enter the letters you see');
  70.  
  71. $form->addRule('captcha''Enter the characters you read in the image',
  72.                'required'null'client');
  73.  
  74. $form->addRule('captcha''What you entered didn\'t match the picture',
  75.                'CAPTCHA'$captcha_question);
  76.  
  77. $form->addElement('submit''''Verify');
  78.  
  79. ?>
  80. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  81.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  82. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  83. <head>
  84. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  85. <title>HTML_QuickForm_CAPTCHA Image example</title>
  86. </head>
  87. <body>
  88. <h1>Image CAPTCHA HTML QuickForm</h1>
  89. <?php
  90. if ($form->validate()) {
  91.     // Prevent re-use of the same CAPTCHA phrase
  92.     $captcha_question->destroy();
  93.  
  94.     echo '<p>Value matched</p>';
  95. else {
  96.     $form->display();
  97. }
  98.  
  99. ?>
  100. <p><a href="qfcaptcha_image.phps">PHP file source for CAPTCHA image code</a></p>
  101. </body>
  102. </html>
  103. <?php
  104.  
  105. highlight_file(__FILE__);
  106.  
  107. ?>

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