function getError() { require_once __DIR__ . '/hn_captcha/hn_captcha.class.php'; $error = false; if ($this->required && (!isset($_POST[$this->name]) || $_POST[$this->name] == '')) { $error = true; } $captcha = new hn_captcha($this->captcha_init, TRUE); if (strtolower($_POST[$this->name]) !== strtolower($captcha->generate_private($_SESSION['library']['php']['form']['standard']['captcha'][$this->name]['public_key']))) { $error = true; } return $error; }
// END CLASS hn_CAPTCHA function scan_dir($dir, $no_dots = FALSE) { $files = array(); $dh = @opendir($dir); if ($dh != FALSE) { while (false !== ($filename = readdir($dh))) { $files[] = $filename; } if ($no_dots) { while (($ix = array_search('.', $files)) > -1) { unset($files[$ix]); } while (($ix = array_search('..', $files)) > -1) { unset($files[$ix]); } } sort($files); } return $files; } session_start(); $spe = scan_dir('inc/ttf/', true); foreach ($spe as $value) { if (strpos($value, '.ttf')) { $fonts[] = $value; } } $array = array('tempfolder' => 'uploads/', 'TTF_folder' => 'inc/ttf/', 'TTF_RANGE' => $fonts, 'chars' => ((int) $_GET['chars'] > 8 or (int) $_GET['chars'] < 1) ? 5 : (int) $_GET['chars'], 'minsize' => ((int) $_GET['minsize'] > 30 or (int) $_GET['minsize'] < 8) ? 8 : (int) $_GET['minsize'], 'maxsize' => ((int) $_GET['maxsize'] > 60 or (int) $_GET['maxsize'] < 14) ? 14 : (int) $_GET['maxsize'], 'captcha_mode' => (isset($_GET['mode']) and $_GET['mode'] == 'mini') ? 'captcha_mini' : 'captcha'); $captcha = new hn_captcha($array, false); $captcha->display_form();
/** * @shortdesc This calls the constructor of main-class for extracting the config array and generating all needed params. Additionally it control the garbage-collector. * @public * @type void * @return nothing * **/ function __construct($config, $secure = TRUE) { // Call Constructor of main-class parent::__construct($config, $secure); // specify counter-filename if ($this->counter_filename == '') { $this->counter_filename = $this->tempfolder . $this->counter_fn_default_basename; } if ($this->debug) { echo "\n<br>-Captcha-Debug: The counterfilename is (" . $this->counter_filename . ")"; } // retrieve last counter-value $test = $this->txt_counter($this->counter_filename); // set and retrieve current counter-value $counter = $this->txt_counter($this->counter_filename, TRUE); // check if counter works correct if ($counter !== FALSE && $counter - $test == 1) { // Counter works perfect, =:) if ($this->debug) { echo "\n<br>-Captcha-Debug: Current counter-value is ({$counter}). Garbage-collector should start at (" . $this->collect_garbage_after . ")"; } // check if garbage-collector should run if ($counter >= $this->collect_garbage_after) { // Reset counter if ($this->debug) { echo "\n<br>-Captcha-Debug: Reset the counter-value. (0)"; } $this->txt_counter($this->counter_filename, TRUE, 0); // start garbage-collector $this->garbage_collector_error = $this->collect_garbage() ? FALSE : TRUE; if ($this->debug && $this->garbage_collector_error) { echo "\n<br>-Captcha-Debug: ERROR! SOME TRASHFILES COULD NOT BE DELETED! (Set the garbage_collector_error to TRUE)"; } } } else { // Counter-ERROR! if ($this->debug) { echo "\n<br>-Captcha-Debug: ERROR! NO COUNTER-VALUE AVAILABLE! (Set the garbage_collector_error to TRUE)"; } $this->garbage_collector_error = TRUE; } }
#captcha { margin-left: 30px; margin-right: 30px; border-style: dashed; border-width: 2px; border-color: #FFD940; } --> </style> </head> <body> <h3>This is a demo of hn_captcha.class.php with a Standalone-Form:</h3> <?php $captcha = new hn_captcha($CAPTCHA_INIT, TRUE); //$captcha =& new hn_captcha($CAPTCHA_INIT); switch ($captcha->validate_submit()) { // was submitted and has valid keys case 1: // PUT IN ALL YOUR STUFF HERE // echo "<p><br>Congratulation. You will get the resource now."; echo "<br><br><a href=\"" . $_SERVER['PHP_SELF'] . "?download=yes&id=1234\">New DEMO</a></p>"; break; // was submitted with no matching keys, but has not reached the maximum try's // was submitted with no matching keys, but has not reached the maximum try's case 2: echo $captcha->display_form(); break; // was submitted, has bad keys and also reached the maximum try's // was submitted, has bad keys and also reached the maximum try's