duandongji2231
2014-03-23 10:26
浏览 53
已采纳

我的codeigniter验证码不生成图像

My CodeIgniter captcha is not generating so I can't show it in my view

Controller

public function login() {
    $this->load->helper('captcha');
    $this->form_validation->set_rules($this->login_rules);
    $userCaptcha = set_value('captcha');
    $word = $this->session->userdata('captchaWord');

    if($this->form_validation->run() == TRUE && strcmp(strtoupper($userCaptcha),strtoupper($word)) == 0) {
        $this->session->unset_userdata('captchaWord');
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        if(!$this->autentifikasi->login($username,$password)) {
            $this->session->set_flashdata('pesan', '<div class="error">Login gagal</div>');
            redirect(site_url('user/login'));
        } else {
            $this->session->set_flashdata('pesan', '<div class="sukses">Anda telah berhasil login, selamat berbelanja.</div>');
            redirect(site_url('user/login'));
        }
    }

    $original_string = array_merge(range(0,9), range('a','z'), range('A', 'Z'));
    $original_string = implode("", $original_string);
    $captcha = substr(str_shuffle($original_string), 0, 6);

    $vals = array(
        'word' => $captcha,
        'img_path' => './captcha/',
        'img_url' => base_url().'user/login/',
        'font_path' => './fonts/texb.ttf',
        'img_width' => '150',
        'img_height' => 30,
        'expiration' => 3600
    );

    $cap = create_captcha($vals);

    $data['image']= $cap['image'];
    $this->session->set_userdata('captchaWord', $captcha);

    $this->template->set_judul('PT. Columbindo Perdana')
        ->set_css('style')
        ->set_parsial('sidebar','sidebar_view',$this->data)
        ->set_parsial('topmenu','top_view',$this->data)
        ->render('user_login',$this->data); 
}

View

    <?php if($this->session->flashdata('pesan')): ?>
    <?php echo $this->session->flashdata('pesan'); ?>
<?php else:?>
    <h2>Silakan Login</h2>
    <?php if(@$error){echo @$error;} ?>
    <?php echo validation_errors(); ?>
    <br />
    <?php echo form_open(site_url(uri_string()),'class="order"'); ?>
    <?php echo form_label('Username'); ?>
    <?php echo form_input('username'); ?>
    <?php echo form_label('Password'); ?>
    <?php echo form_password('password'); ?>
    <?php echo form_label('Captcha'); ?>
    <?php echo $image; ?>
    <?php echo form_input('captcha'); ?>
    <?php echo form_submit('submit','Login'); ?>
    <?php echo form_close(); ?>
    <br />
    Anda belum memiliki akun? Silakan daftar <a href="<?php echo site_url('user/register') ;?>">disini</a>.
<?php endif ?>

As I know I didn't have captcha folder or font folder, is it still will be generate it self without those 2 folders? I already try what i can from some solved problem but it's still not working. no error but the captcha image not show up.

please help me.

1条回答 默认 最新

相关推荐 更多相似问题