<?phpsession_start();//随机码的个数
$_rnd_code = 4;//创建随机码
for ($i=0; $i<$_rnd_code; $i++) {
$_nmsg .= dechex(mt_rand(0, 15));
}//保存在session
$_SESSION['code'] = $_nmsg;//长和高
$_width = 75;
$_height = 25;//创建一张图像
$_img = imagecreatetruecolor($_width, $_height);//白色
$_white = imagecolorallocate($_img, 255, 255, 255);//填充
imagefill($_img,0,0,$_white);$_flag = false;if ($_flag) {
//黑色,边框
$_black = imagecolorallocate($_img, 0, 0, 0);
imagerectangle($_img, 0, 0, $_width-1, $_height-1, $_black);
}//随即画出6个线条
for ($i=0; $i<6; $i++) {
$_rnd_color = imagecolorallocate($_img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imageline($_img, mt_rand(0, $_width), mt_rand(0, $_height), mt_rand(0, $_width), mt_rand(0, $_height), $_rnd_color);
}//随即雪花
for ($i=0; $i<100; $i++) {
$_rnd_color = imagecolorallocate($_img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255));
imagestring($_img, 1, mt_rand(1, $_width), mt_rand(1, $_height), '*', $_rnd_color);
}//输出验证码
for ($i=0; $i<strlen($_SESSION['code']); $i++) {
$_rnd_color = imagecolorallocate($_img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200));
imagestring($_img, 5, $i*$_width/$_rnd_code+mt_rand(1, 10), mt_rand(1, $_height/2), $_SESSION['code'][$i], $_rnd_color);
}//输出图像
header('Content-Type: image/png');
imagepng($_img);//销毁
imagedestroy($_img);?>以在代码在PHP 5.2.6版本中运行是正常的.
但是我将此代码放在 PHP 5.3.3 中后就不能正常运行了.. 
请问,我需要修改些什么地方,才能够在5.3.3中运行?

解决方案 »

  1.   

    没印象 PHP 新版本有升级改动 图像函数. 你将出错信息打开 看看什么提示
      

  2.   

    看下你的5.3版本下的php.ini中GD库扩展有没有打开
      

  3.   

    我有打开GD库扩展啊.. 
    这么坑爹啊,请问会不会有其它什么问题导致不能正常运行呢?
    因为我是使用的WAMP.. 前者是PHP 5.2.6  运行正常!
    后来升级后过WAMP 后PHP也升级到5.3.3了,所以这个坑爹的问题就出来了.. 
      

  4.   

    error_reporting(E_ALL);
    ini_set("display_errors",1);
    把错误信息提示出来
      

  5.   

    提示: 图像 “http://localhost/guest/test.php” 因其本身有错无法显示。你看你们都已经有人能正常运行了,我的点解就不能运行呢? 我用的是WampServer 2.1a