【问题标题】:Codegnither captcha image is not displayingCodegnither 验证码图像未显示
【发布时间】:2014-02-10 18:29:33
【问题描述】:

我真的在网上冲浪,甚至在这个论坛上也发布过类似的问题,但我发现大多数问题都没有得到回答。

无论如何,我也想在这里发布我的问题,如果有人能尽快提供帮助,我将不胜感激。

我在 localhost 中执行此操作,这是我的控制器,

   public function register(){

            $this->load->helper('captcha');

            $captcha = array(
                'word' => 'Random 123',
                'imag_path' => './captcha/',
                'img_url' => base_url() . 'captcha/',
                'font_path' => './fonts/arial.ttf',
                'img_width' => '300',
                'img_height' => '50',
                'expiration' => '3600',
            );
            print_r($captcha);
            $img = create_captcha($captcha);
            $data['image'] = $img['image'];

            if(!$_POST){
            $this->load->view('public/register', $data);
            return true;
        }
    }

我的视图有以下脚本,

<?php
    echo $image;
?>

问题:验证码图像未显示

仅供参考:在我的研究中,我发现许多提到的人首先考虑以下几点。

1) 检查“captcha”文件夹是否为777模式

2) 检查 GD 库是否已加载

我确实检查了以上几点,但我不是 100% 确定,因为我看不到本地文件夹权限设置为 777(我使用的是 windows 7 32 位)。当右键单击并检查“验证码”文件夹属性时,它设置为

属性 只读(选中) 隐藏(未选中)

这是正确的吗?如果是这样,那么您知道为什么我的验证码图像无法正常工作吗?

如果您需要更多详细信息,请告诉我?

【问题讨论】:

  • 创建一个名为captcha的文件夹,然后使用base_ulr()到img_path
  • 我已经在应用程序文件夹中有验证码和字体文件夹。我什至检查了将验证码文件夹添加到上一级,但没有奏效。

标签: php codeigniter security captcha


【解决方案1】:

尝试使用此代码

<?php 

    $pool = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    $captcha = substr( str_shuffle( $pool ), 0, 5 );  


   $vals = array(
                'word' => $captcha,
    'img_path'   => 'front_images/captcha/',
    'img_url'    => base_url().'front_images/captcha/',
    'img_width'  => 120,
    'img_height' => 35,
    'font_path' => './system/fonts/texb.ttf',
    'expiration' => 3600 //1 houre
  );

  $cap = create_captcha($vals);
  echo $cap['image']

?>

【讨论】:

  • 感谢您的回复,但结果仍然是相同的验证码图像未显示。我什至按照应用程序 front_image/captcha/ 创建了 front_images 文件夹
  • 对不起,我忘了包括helper。你包括它吗?
  • 验证码助手?如果是,则添加为 $this->load->helper('captcha');
【解决方案2】:

您在配置数组中输入错误,而不是 imag_pathimg_path。 还要确保以下几点:

1. `img_path` or `img_url` is set properly.
2. If you have specified `img_path`, then make sure such a directory exists.
3. Make sure the `img_path` is `writable`.
4. Make sure `gd` library is installed.

【讨论】:

  • 感谢您发现错误。但是我尝试了@Azam Alvi 示例,但它没有用。另外能否请您确认如何检查,是否安装了 GD 库?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多