zka*_*oca 1 php captcha codeigniter
我正在尝试创建一个登录页面。我想使用 CI 的助手添加验证码图像但无法成功。
登录.php
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));
}
}
Run Code Online (Sandbox Code Playgroud)
login_form.php获取验证码图像,但boolean false在我使用时显示var_dump它包含的内容。
<?php var_dump($captcha); //boolean false?>
Run Code Online (Sandbox Code Playgroud)
它看起来像是create_captcha()返回false而不是图像。所以我无法获得图像。但是我按照教程说的做了。
根据该create_captcha函数的CodeIgniter API,这些是获取 Boolean 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: }
Run Code Online (Sandbox Code Playgroud)
所以请确保:
您发送 img_path 和 img_url 参数(请注意我关于参数名称中可能存在拼写错误的评论)。
img_path 是一个现有的目录,它也是可写的
您已安装 GD 扩展。
路径/网址
我相信这是因为你正在使用base_url() . 'captcha'你的img_path.
base_url()以以下格式返回一个网址:http://www.domain.com/而路径应该是另一种格式(相对),例如:./directory/captache/。
| 归档时间: |
|
| 查看次数: |
1616 次 |
| 最近记录: |