Php 无法在CodeIgniter中获取验证码图像
我正在尝试创建一个登录页面。我想使用CI的助手添加验证码图像,但未能成功 Login.phpPhp 无法在CodeIgniter中获取验证码图像,php,codeigniter,captcha,Php,Codeigniter,Captcha,我正在尝试创建一个登录页面。我想使用CI的助手添加验证码图像,但未能成功 Login.php class Login extends CI_Controller { public function __construct() { parent::__construct(); } public function index() { $this->load->helper(array('form', 'url', 'captc
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->helper(array('form', 'url', 'captcha'));
$captchaSettings = array(
'img_path' => base_url() . 'captcha',
'img_url' => base_url() . 'captcha',
'font_path' => base_url() . 'system/fonts/captcha4.ttf',
'img_width' => '300',
'img_height' => '40',
'expiration' => '3600',
'word_length' => 6,
'font_size' => 16,
'img_id' => 'captchaImage',
'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
// White background and border, black text and red grid
'colors' => array(
'background' => array(255, 255, 255),
'border' => array(255, 255, 255),
'text' => array(0, 0, 0),
'grid' => array(255, 40, 40)
)
);
$dataCaptcha = create_captcha($captchaSettings);
$this->load->view('login_form', array('captcha' => $dataCaptcha));
}
}
当我使用var\u dump
查看它包含的内容时,login\u form.php获取captcha图像,但显示boolean false
<?php var_dump($captcha); //boolean false?>
它看起来像是
create\u captcha()
返回false
而不是图像。所以我无法得到图像。但是我按照教程所说的做了。根据函数的CodeIgniter API,这些可能是导致布尔值为false的原因
61: if ($img_path == '' OR $img_url == '')
62: {
63: return FALSE;
64: }
65:
66: if ( ! @is_dir($img_path))
67: {
68: return FALSE;
69: }
70:
71: if ( ! is_writable($img_path))
72: {
73: return FALSE;
74: }
75:
76: if ( ! extension_loaded('gd'))
77: {
78: return FALSE;
79: }
因此请确保:
base\u url()验证码“
作为您的img\u路径
。
base\u url()
返回格式为:http://www.domain.com/
虽然路径应该是另一种格式(相对),例如:/directory/captache/
根据函数的CodeIgniter API,这些可能是获取布尔值false的原因
61: if ($img_path == '' OR $img_url == '')
62: {
63: return FALSE;
64: }
65:
66: if ( ! @is_dir($img_path))
67: {
68: return FALSE;
69: }
70:
71: if ( ! is_writable($img_path))
72: {
73: return FALSE;
74: }
75:
76: if ( ! extension_loaded('gd'))
77: {
78: return FALSE;
79: }
因此请确保:
base\u url()验证码“
作为您的img\u路径
。
base\u url()
返回格式为:http://www.domain.com/
而路径应该是另一种格式(相对),类似于:/directory/captache/
使用captcha帮助程序
要求。是的,应该是。更改后,它仍然返回布尔false。考虑在<代码> BaseIurl()之后添加<代码> /<代码>。验证码“。顺便问一下,为什么path
和url
使用相同的值?URL应该包括www..
,而路径类似于:/directory/..
使用验证码助手的要求。是的,应该是。更改后,它仍然返回布尔false。考虑在<代码> BaseIurl()之后添加<代码> /<代码>。验证码“
。顺便问一下,为什么path
和url
使用相同的值?URL应该包括www..
而路径类似于:/directory/..
它对我有效我更改了我的代码如下**'img_path'=>'img/captcha/,'img_URL'=>base_URL()。'img/captcha/'**
它对我有效我更改了代码如下**'img_path'=>'img/captcha/,'img_URL'=>base_URL().“img/captcha/”**