php验证码,php验证码的问题,php验证码不能正常显示,是乱码,有哪位高人能够解决,奉献两万积分

来源:百度知道 编辑:UC知道 时间:2024/05/30 23:26:50
整个php网页代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<?php
Header("content-type: image/png");

srand((double)microtime()*1000000);
$randval = rand();

$font = 4;
$im = imagecreate(120,31);
$background_color = ImageColorAllocate($im,0,0,0);
$foreground_color = ImageColorAllocate($im,250,250,250);
imagefill($im,0,0,$background_color);
$px = (imagesx($im)-8.3*strlen($randval))/2;
ImageString($im,$font,$px,15.5,$randval,$foreground_color);
Imagepng($im);
ImageDestroy($im);
?>

上面的错了,可参见我的回答http://zhidao.baidu.com/question/12000285.html

还是直接贴到这里吧:
要么输出HTML文本,要么输出图像数据流,没有混合输出的,浏览器不支持。
有两种方法改造程序:
一、可以把程序改成这样:
<?php
$self = $_SERVER['PHP_SELF'];
if(!$_GET['src']){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<img src="<?="$self?src=1"?>" />
</body>
</html>
<?php
}else{
Header("content-type: image/png");
srand((double)microtime()*1000000);
$randval = rand();
$font = 4;
$im = imag