Reputation: 67
How to create captcha in codeigniter 2.1.0 load helper codeigniter ? when i have model m_captcha :
function __construct()
{
parent::__construct();
}
function setCaptcha()
{
$this->load->helper('captcha');
$vals = array(
'img_path' => './asset/captcha',
'img_url' => base_url().'/asset/captcha',
'expiration' => 3600,// one hour
'font_path' => './system/fonts/georgia.ttf',
'img_width' => '140',
'img_height' => 30,
'word' => random_string('numeric', 6),
);
$cap = create_captcha($vals);
if ($cap)
{
$capdb = array(
'captcha_id' => '',
'captcha_time' => $cap['time'],
'ip_address' => $this->CI->input->ip_address(),
'word' => $cap['word']
);
$query = $this->db->insert_string('captcha', $capdb);
$this->db->query($query);
}else {
return "Captcha not work" ;
}
return $cap['image'] ;
}
and i have controller c_login :
function __construct()
{
parent::__construct();
$this->load->model('m_captcha');
}
public function index()
{
$this->load->helper('captcha');
$data = $this->m_captcha->setCaptcha();
$this->load->view('login/v_form',$data);
}
and i have view :
<?php echo form_open('c_login'); ?>
<?php echo $cap['image']; ?>
<?php echo form_error('captcha');?>
<?php echo form_close(); ?>
why the captcha cannot show in view ? position folder and image captcha in sms/asset/captcha . sms is folder root Codeigniter.
Upvotes: 1
Views: 9096
Reputation: 7618
Why don't use reCaptcha instead? http://codeigniter.com/wiki/ReCAPTCHA It's easy to implement!
Upvotes: 0
Reputation: 646
<?php echo $cap['image']; ?>
is the problem.
Lets check the flow once again, you are returning the $cap['image']
from model.
And after that, you accepted that in $data
in controller.
It must be something $data['capcha']
so that you can access it using $capcha
in view.
Very Simple.
Upvotes: 1