CodeIgniter 2 - 验证码助手?

时间:2011-03-04 05:04:20

标签: codeigniter captcha codeigniter-2

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

我想我已经按照文档的所有步骤进行了操作但是我没有得到任何事件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);

}

我的模特
   $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);
}

1 个答案:

答案 0 :(得分:1)

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


    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);
    }