Php codeigniter中的图像验证码

Php codeigniter中的图像验证码,php,codeigniter,Php,Codeigniter,我正在用CodeIgniter做我的项目。我试图调用索引文件中的captcha.php文件。此captcha文件位于文件夹文件中。当前,未查看验证码图像。我需要在图像中显示随机数 captcha.php <?php session_start(); $string = ''; for ($i = 0; $i < 5; $i++) { $string .= chr(rand(97, 122)); } $_SESSION['random_number'] = $string

我正在用CodeIgniter做我的项目。我试图调用索引文件中的
captcha.php
文件。此captcha文件位于文件夹文件中。当前,未查看验证码图像。我需要在图像中显示随机数

captcha.php

<?php
session_start();

$string = '';

for ($i = 0; $i < 5; $i++) {
    $string .= chr(rand(97, 122));
}

$_SESSION['random_number'] = $string;

$dir = 'fonts/';

$image = imagecreatetruecolor(165, 50);

// random number 1 or 2
$num = rand(1,2);
if($num==1)
{
    $font = "PT_SANS-BOLD_1.TTF"; // font style
}
else
{
    $font = "PT_SANS-ITALIC_1.TTF";// font style
}

// random number 1 or 2
$num2 = rand(1,2);
if($num2==1)
{
    $color = imagecolorallocate($image, 113, 193, 217);// color
}
else
{
    $color = imagecolorallocate($image, 163, 197, 82);// color
}

$white = imagecolorallocate($image, 255, 255, 255); // background color white
imagefilledrectangle($image,0,0,399,99,$white);

imagettftext ($image, 30, 0, 10, 40, $color, $dir.$font, $_SESSION['random_number']);

header("Content-type: image/png");
imagepng($image);

?>

in html file

<img src="<?= base_url();?>files/captcha.php" alt="" id="captcha" />

在html文件中
文件/captcha.php“alt=”“id=“captcha”/>

这不是对您问题的回答,而是您可以选择的备选方案

这么多验证码脚本已经可用,也许你可以使用其中的一些,而不是再次编码

检查


如果选择此选项,请确保字体放置在正确的位置。

这是codeigniter验证码还是自定义验证码?jquery验证码[链接]()从这个链接我得到了验证码。你能粘贴你的控制器和视图吗?你的控制台对IMG的
src
说了些什么?你说我已经试过了,但它仍然没有在imagecaptcha.php中显示它的内容?宽度=100&height=40&characters=5/>像这样,我只需要给出