我在我的form.the中使用了验证码,下面是验证码的创建
<?php
session_start();
$string = '';
for ($i = 0; $i < 5; $i++)
{
$string .= chr(rand(97, 122));
}
$_SESSION['rand_code'] = $string;
$dir = 'fonts/';
$image = imagecreatetruecolor(150,60) or die('Cannot Initialize new image ');
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 200, 100, 90);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image,0,50,150,100,$black);
imagettftext ($image, 30, 0, 10, 40, $color, $dir."BauhausMedium.ttf", $_SESSION['rand_code']);
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
?> 在其他页面中,我使用img标记调用此代码。
但问题是,在该页面中,我想要文本框中的captcha图像。我使用$_ session‘’rand_code‘;但我显示的是前一个会话的值,即前一个captcha图像值。我想要该页面中的当前图像值?
发布于 2011-01-24 18:11:12
您将在加载表单后访问验证码,因为表单中的图像实际上触发了验证码。
您应该只在表单提交后检查验证码。
发布于 2011-01-24 18:16:35
一种方法是创建随机代码,并将其保存在具有img标记的页面的会话中。在创建图像的页面上,只需阅读会话。
https://stackoverflow.com/questions/4780753
复制相似问题