wasksofts / codeigniter-math-captcha
captcha verification with math quiz
v1.0
2019-06-02 12:08 UTC
Requires
- php: ^5.6|^7
This package is auto-updated.
Last update: 2025-04-15 14:22:00 UTC
README
Math CAPTCHA Library for CodeIgniter, generate random sum of numbers
Install
Install the libray for using by autoload.
$ composer require wasksofts/codeigniter-math-captcha
usage
controller
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);
}
}
add this html part to your form
<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>
View Usage
Bugs and feature requests
Have a bug or a feature request? please email mukamanusteven@gmail.com