【问题标题】:CodeIgniter 2 - captcha helper?CodeIgniter 2 - 验证码助手?
【发布时间】:2023-11-09 17:07:01
【问题描述】:

我似乎无法让 CI2 的验证码助手工作...有人能指出我做错了什么吗?

我想我已经按照文档中的所有步骤进行了操作,但我没有收到任何事件 a print_r(get_defined_vars()) 没有显示任何内容... :(

我的控制器


function index()
{
$this->load->helper('form'); $this->load->helper('captcha'); $this->load->model('captcha');
   $vals = array(
    'word'   => 'Random word',
    'img_path'   => '../images/captcha/',
    'img_url'    => 'http://mysite/images/captcha/',
    'font' => '../../system/fonts/texb.ttf',
    'img_width'  => '150',
    'img_height' => 30,
    'expiration' => 7200,
    "time" => time()
   );

   $data['cap'] = create_captcha($vals);

   $cap = array(
    'captcha_time'  => $vals['time'],
    'ip_address'    => $this->input->ip_address(),
    'word'   => $vals['word']
   );

   $this->captcha_model->insert_captcha($cap);
   //print_r(get_defined_vars());   

   $data['main_content'] = 'admin/landing.php';
   $this->load->view('includes/template', $data);

}

我的模特

function input_captcha($data)
{
    $query = $this->db->insert_string('captcha', $data);
    $this->db->query($query);
}
我的观点

<section>
    <h3>You must captcha this captcha before proceeding to your demise!</h3>
    <article>
        <?php echo form_open('admin/auth');?>
            <p>Who the F are you?</p>
            <?php echo form_input('email', 'your real email!');?>
            <br>
            <?php    echo 'Submit the word you see below:';?>
            <br>
            <?php    echo $cap['image'];?>
            <br>
            <?php    echo '<input type="text" name="captcha" value="" />';   ?>
<br> <?php echo form_submit('submit', 'Send It!');?>
<?php echo form_close();?> </article> </section>

【问题讨论】:

  • 您的模型正在加载吗?您加载它的方式,似乎您的型号名称不是以第一个大写字母开头?它应该说明: $this->load->model('Captcha');

标签: codeigniter captcha codeigniter-2


【解决方案1】:

问题在于图像的路径。有一件事,即使将日志阈值设置为四,我也没有得到任何问题的迹象。我将它设置为绝对路径,一切正常......


    function index()
    {   
        $this->load->helper('form');
        $this->load->helper('captcha');
        $this->load->model('captcha_model');

        $vals = array(
            'img_path'   => '/var/www/mysite.com/images/captcha/',
            'img_url'    => 'http://mysite.com/images/captcha/',
            'font' => '../../system/fonts/texb.ttf',
            'img_width'  => '150',
            'img_height' => 30,
            'expiration' => 7200,
            "time" => time()
            );

        $data['cap'] = create_captcha($vals);

        $cap = array(
            'captcha_time'  => $data['cap']['time'],
            'ip_address'    => $this->input->ip_address(),
            'word'   => $data['cap']['word']
            );

        $this->captcha_model->add_captcha($cap);

        $data['main_content'] = 'admin/landing.php';
        $this->load->view('includes/template', $data);
    }

【讨论】: