显示php验证码图像

时间:2014-07-27 10:52:00

标签: php forms captcha

在我的html表单中显示我的验证码图像时遇到大问题 下面引用的“captcaImageOutput.php”文件在浏览器中打开时效果很好(下面也复制了这个代码)但是我在网络表单中得到了一个损坏的图像?

//编辑 - 将captchaOutput.php添加到最后的代码 //非常感谢您的回复! :)

//CODE FOR HTML FORM
<form action = "captchaOutput.php" method = "POST">
<label for ="verify"><h3>And finally,verify your human!</h3></label>    
<input type = "text" id = "verify" name = "verify" />   
<img src="captchaImageOutput.php" /> 
</form> 

//CODE FOR PHP CAPTCHA IMAGE
<?php
session_start();
$_SESSION['secure']=rand(1000,9999);
?>
<img src = "captchaCode.php" /><br> 

//CODE FOR CAPTCHA GENERATION
 <?php
 session_start();
 header('Content-type: image/jpeg');

 $text = $_SESSION['secure'];
 $font_size = 20;

 $image_width = 110;
 $image_height = 35;

 $image = imagecreate($image_width,$image_height);
 imagecolorallocate($image,255,255,255); 
 $text_color = imagecolorallocate($image,0,0,0); 

for($i=0; $i<30; $i++)
  {   
    $x1 = rand(1,100);
    $y1 = rand(1,100);
    $x2 = rand(1,100);
    $y2 = rand(1,100);
    imageline($image,$x1,$y1,$x2,$y2,$text_color);
    imagesetpixel($image,rand() % $image_width, rand() % $image_height,$text_color);
 }

imagettftext($image,$font_size,0,15,30,$text_color,'font.ttf',$text);
imagejpeg($image);

?>

0 个答案:

没有答案