【问题标题】:nothing showing in captcha code of codeignitercodeigniter 的验证码中没有显示任何内容
【发布时间】:2023-11-10 17:10:02
【问题描述】:

我的 gd2 图像库有问题 这是我的索引控制器

public function index()
    {   
        $config['image_library'] = 'gd2';
         $this->load->library('image_lib', $config);
        $vals = array(
                'img_path'   => './captcha/',
                'img_url'    => base_url().'public/img/captcha/',
                'img_width'  => '200',
                'img_height' => 30,
                'border' => 0, 
                'expiration' => 7200,
                );

                 // create captcha image
                $cap = create_captcha($vals);
                print_r($cap);
                // store image html code in a variable
                $arrData['image'] = $cap['image'];

               // store the captcha word in a session
                $this->session->set_userdata('word', $cap['word']);
        $arrData['middle'] = 'contact';
        $this->load->view('template',$arrData);
    }

上面这段代码是我的控制器的索引函数

这是我的看法

<div class="enquiry-deatils">
          <label>Type character * :</label>
          <input type="text" placeholder="" class="captcha"/>
          <label><img src="images/capcha.jpg" /></label>
          <?php echo $image;  // this will show the captcha image ?>
        </div>

我不知道是什么错误,它什么也没显示

【问题讨论】:

  • 你检查过萤火虫中的图像元素吗?
  • 是的,它显示空白没有图像标签
  • 然后执行 print_r($arrData);在传递给视图之前在控制器中。
  • 这是给我看这个输出数组([image] => [middle] => contact)

标签: php codeigniter captcha recaptcha


【解决方案1】:

试试这个- 提供 img_path 和 img_url 的完整路径。像这样-

  $vals = array(
            'img_path'   => 'mysite/public/img/captcha/',
            'img_url'    => 'mysite/public/img/captcha/',
            'img_width'  => '150',
            'img_height' => 30,
            'expiration' => 7200,
            "time" => time()
            );

【讨论】:

  • 抱歉没有工作仍然会出现空白。$arrData['image] 中没有任何内容
  • 但是,这次是在验证码文件夹中生成的图像吗?见
  • 没有还是空文件夹
  • 那么我建议,使用不同的验证码库。您的验证码库肯定存在一些配置问题
最近更新 更多