下面是生成验证码代码,结果编程之家本站测试过,没错误贴上来的。如果有什么不懂的地方可以回复,编程之家会为你解释不了解之处。希望能对你有所收获。 session_start(); $nums = rand(1000,9999); $_SESSION[nums]=$nums; $imgs = ImageCreatetruecolor(100, 35); $one = Imagecolorallocate($imgs, 0, 0, 0); $two = Imagecolorallocate($imgs, rand(0, 255), rand(0, 255), rand(0, 255)); $thr = Imagecolorallocate($imgs, rand(50, 200), rand(100, 255), rand(150, 255)); Imagestring($imgs, 6, rand(5, 60), rand(3, 18), $nums, $two); for ($i = 1; $i imageline($imgs, rand(0, 0), rand(0, 25), rand(70, 100), rand(0, 25), $thr); } for ($i = 1; $i imagesetpixel($imgs,rand()0,rand()5,$two); } Header("Content-type:image/jpeg"); imagejpeg($imgs); ?>