我正在 CodeIgniter 中做我的项目。我正在尝试captcha.php
在索引文件中调用文件。文件夹文件中的此验证码文件。目前,验证码图像未查看。我需要在图像中显示随机数。
验证码.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" />