简体   繁体   English

Codeigniter-验证码助手不起作用

[英]codeigniter - captcha helper not working

captcha function in controller : 控制器中的验证码功能:

public function captcha(){
    $this->load->helper('captcha');
    $captcha = array(
        'word' => 'Random 123',
        'img_path' => './captcha/',
        'image_url' => base_url() . 'captcha/',
        'font_path' => './fonts/LucidaTypewriterBold.ttf',
        'img_width' => '300',
        'img_height' => '50',
        'expiration' => '3600',
    );

    $img = create_captcha($captcha);
    $dataf['image'] = $img['image'];

    $this->load->view('captcha_view', $dataf);
}

captcha view file : 验证码查看文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Enter Captcha</title>

</head>
<body>
    <h3>Creating CAPTCHA</h3>
    <?php 

        echo $image;
        // echo '<br/>Word: ' .$word;
        // echo '<br/>time: ' .$time;

    ?>
</body>
</html>

This doesn't load the captcha image, only the heading 'Creating CAPTCHA'. 这不会加载验证码图片,只会加载标题“ Creating CAPTCHA”。 Also,there are no errors displayed. 此外,没有显示错误。

I am a newbie to php/codeigniter , please help. 我是php / codeigniter的新手,请帮忙。

Try this 尝试这个

Loading Captcha should be like this 加载验证码应该是这样的

$captcha_array = array(
    'name' => 'captcha',
    'class' => 'input_box',
    'color' => 'white',
    'placeholder' => '',
    'id' => 'captcha'
);
echo form_input($captcha_array);

And your controller code should also be change as well. 而且您的控制器代码也应该更改。 You need session help too 您也需要会话帮助

Check this tutorial as well 也检查本教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM