How to create captcha in codeigniter 2.1.0 load helper codeigniter ? when i have model m_captcha :
如何在codeigniter 2.1.0中创建验证码加载助手codeigniter?当我有模型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 :
我有控制器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.
为什么验证码无法显示在视野中? sms / asset / captcha中的位置文件夹和图像验证码。短信是文件夹根Codeigniter。
2 个解决方案
#1
1
<?php echo $cap['image']; ?>
is the problem.
<?php echo $ cap ['image']; ?>是问题所在。
Lets check the flow once again, you are returning the $cap['image']
from model.
让我们再次检查流程,你从模型中返回$ cap ['image']。
And after that, you accepted that in $data
in controller.
之后,你在控制器的$ data中接受了它。
It must be something $data['capcha']
so that you can access it using $capcha
in view.
它必须是$ data ['capcha'],以便您可以使用$ capcha在视图中访问它。
Very Simple.
很简单。
#2
0
Why don't use reCaptcha instead? http://codeigniter.com/wiki/ReCAPTCHA It's easy to implement!
为什么不使用reCaptcha? http://codeigniter.com/wiki/ReCAPTCHA这很容易实现!
#1
1
<?php echo $cap['image']; ?>
is the problem.
<?php echo $ cap ['image']; ?>是问题所在。
Lets check the flow once again, you are returning the $cap['image']
from model.
让我们再次检查流程,你从模型中返回$ cap ['image']。
And after that, you accepted that in $data
in controller.
之后,你在控制器的$ data中接受了它。
It must be something $data['capcha']
so that you can access it using $capcha
in view.
它必须是$ data ['capcha'],以便您可以使用$ capcha在视图中访问它。
Very Simple.
很简单。
#2
0
Why don't use reCaptcha instead? http://codeigniter.com/wiki/ReCAPTCHA It's easy to implement!
为什么不使用reCaptcha? http://codeigniter.com/wiki/ReCAPTCHA这很容易实现!