本文整理汇总了PHP中Captcha::invalid_count方法的典型用法代码示例。如果您正苦于以下问题:PHP Captcha::invalid_count方法的具体用法?PHP Captcha::invalid_count怎么用?PHP Captcha::invalid_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Captcha
的用法示例。
在下文中一共展示了Captcha::invalid_count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: page1
public function page1()
{
$view = new View('signup/page1');
// Load Captcha library, you can supply the name of the config group you would like to use.
$captcha = new Captcha();
// Form info
$form = array('username' => '', 'password' => '', 'password_confirm' => '', 'email' => '');
// copy the form as errors, so the errors will be stored with keys corresponding to the form field names
$errors = $form;
// 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) {
// Add some rules, the input field, followed by a list of checks, carried out in order
$valid_c = Captcha::valid($this->input->post('captcha_response'));
$this->user = ORM::factory('user');
$post = $this->input->post();
if ($this->user->validate($post) && $valid_c) {
$this->user->save();
$this->session->set('uid', $this->user->id);
$this->user->add(ORM::factory('role', 'login'));
$this->auth->login($this->user, $post['password']);
url::redirect('/signup/page2');
exit(0);
} else {
// repopulate the form fields
$form = arr::overwrite($form, $post->as_array());
$errors = arr::overwrite($errors, $post->errors('signup_errors'));
if (!$valid_c) {
$errors['captcha_response'] = "Invalid";
}
}
}
// Put the vars in the template
$view->set("errors", $errors);
$this->template->content = $view;
$this->template->content->captcha = $captcha;
$this->template->content->form = $form;
}
示例2: captcha
/**
* 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();
}