我的codeigniter验证码未生成图像 [英] my codeigniter captcha not generating image

查看:96
本文介绍了我的codeigniter验证码未生成图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CodeIgniter验证码未生成,因此无法在我的视图中显示

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

控制器

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

查看

    <?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 ?>

我知道我没有验证码文件夹或字体文件夹,是否仍会生成它自己没有那些2个文件夹?我已经尝试了解决一些问题的方法,但是仍然无法正常工作。没错,但是验证码图片没有显示。

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.

请帮助我。

推荐答案

问题是您正在将 $ this-> data 传递给视图,但是您将生成的图像分配给 $ data 。因此,您需要将其更改为

The problem is that you are passing $this->data to your view but you are assigning the image generated to $data. So you need to change it from

$data['image']= $cap['image'];

$this->data['image']= $cap['image'];

如果这不起作用,请确保将图片保存到验证码目录('img_path'=>'./captcha /')是可写的,可以是666或777。您可以通过 chmod 777 captcha / 在命令行上。此外,还要确保在 php.ini

If that doesn't work then make sure the captcha directory you are saving the image to ('img_path' => './captcha/') is writable, either 666 or 777. You can do this be doing chmod 777 captcha/ on the command line. Also make sure that the GD image library extension is enabled in your php.ini

这篇关于我的codeigniter验证码未生成图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆