Allows conditional ignoring of captcha rendering if skipped in the config.
public static render ( Gdn_Controller $controller ) : null; | ||
$controller | Gdn_Controller | |
Результат | null; |
/** * 输出缩略图 */ public function action_default($type = '') { $width = 80; $height = 30; if ($type && preg_match('#^([0-9]+)x([0-9]+)$#i', $type, $m)) { if ($m[1] > 0) { $width = $m[1]; } if ($m[1] > 0) { $height = $m[2]; } } Captcha::render(array('width' => $width, 'height' => $height)); }
/** * Demontrates how to use the Captcha library. */ public function captcha() { // Look at the counters for valid and invalid // responses in the Session Profiler. new Profiler(); // Load Captcha library, you can supply the name // of the config group you would like to use. $captcha = new Captcha(); // Ban bots (that accept session cookies) after 50 invalid responses. // Be careful not to ban real people though! Set the threshold high enough. if ($captcha->invalid_count() > 49) { exit('Bye! Stupid bot.'); } // Form submitted if ($_POST) { // Captcha::valid() is a static method that can be used as a Validation rule also. if (Captcha::valid($this->input->post('captcha_response'))) { echo '<p style="color:green">Good answer!</p>'; } else { echo '<p style="color:red">Wrong answer!</p>'; } // Validate other fields here } // Show form echo form::open(); echo '<p>Other form fields here...</p>'; // Don't show Captcha anymore after the user has given enough valid // responses. The "enough" count is set in the captcha config. if (!$captcha->promoted()) { echo '<p>'; echo $captcha->render(); // Shows the Captcha challenge (image/riddle/etc) echo '</p>'; echo form::input('captcha_response'); } else { echo '<p>You have been promoted to human.</p>'; } // Close form echo form::submit(array('value' => 'Check')); echo form::close(); }
/** * @covers Xoops\Form\Captcha::render * @covers Xoops\Form\Captcha::__construct */ public function testRender() { $value = $this->object->render(); $this->assertTrue(is_string($value)); }
<?php /** * This script generates an image containing an asymmetric key used by login. * * @author Richard K. Szabó <*****@*****.**> * @file verify.php * @copyright MIT */ $auto_login = false; require "../../include/iq.php"; $captcha = new Captcha(10); $session->set(Captcha::KEY_LOGIN, $captcha->getCode(), Captcha::LIFETIME_LOGIN); $captcha->render();
echo $this->Form->Input('PasswordMatch', 'password', array('Wrap' => TRUE)); echo '<span id="PasswordsDontMatch" class="Incorrect" style="display: none;">' . t("Passwords don't match") . '</span>'; ?> </li> <?php $this->fireEvent('ExtendedRegistrationFields'); ?> <li> <?php echo $this->Form->label('Why do you want to join?', 'DiscoveryText'); echo $this->Form->textBox('DiscoveryText', array('MultiLine' => true, 'Wrap' => TRUE)); ?> </li> <?php Captcha::render($this); ?> <?php $this->fireEvent('RegisterFormBeforeTerms'); ?> <li> <?php echo $this->Form->CheckBox('TermsOfService', $TermsOfServiceText, array('value' => '1')); ?> </li> <li class="Buttons"> <?php echo $this->Form->button('Apply for Membership', array('class' => 'Button Primary')); ?>
public function action_index() { Captcha::render(); }