wasksofts / codeigniter-math-captcha
使用数学测试进行验证码验证
v1.0
2019-06-02 12:08 UTC
Requires
- php: ^5.6|^7
This package is auto-updated.
Last update: 2024-09-15 12:50:40 UTC
README
CodeIgniter 数学 CAPTCHA 库,生成随机数字之和
安装
安装库以通过自动加载使用。
$ composer require wasksofts/codeigniter-math-captcha
用法
控制器
class Test extends CI_Controller
{
public function index()
{
$this->load->library('mathcaptcha');
$this->form_validation->set_rules('captcha', 'captcha', 'trim|xss_clean|required|callback__check_captcha');
if ($this->form_validation->run()) {
echo 'success';
}
//how to controll whether to use this library or another
$data['show_captcha'] = TRUE;
$data['captcha_html'] = $this->mathcaptcha->create_captcha();
$this->load->view('form_view', $data);
}
//this is callback function for validation
public function _check_captcha($code)
{
return $this->mathcaptcha->_check_captcha($code);
}
}
将以下 HTML 部分添加到您的表单中
<form method="post" action="<?= $this->uri->uri_string() ?>">
<table>
<tr>
<td colspan="3">
<p>Answer this math quiz : <?php echo $captcha_html; ?></p>
</td>
</tr>
<tr>
<td>
<?= form_input(["id" => "captcha", "name" => "captcha", "type" => "text", "placeholder" => "answer", "required" => "true"]); ?> <br>
<?php echo form_error('captcha'); ?> <br />
</td>
</tr>
</table>
<button type="submit">Submit</button>
</form>
查看用法
错误和功能请求
Have a bug or a feature request? please email mukamanusteven@gmail.com