书上抄的一个图片验证码,为什么只输出一位。新手求解!!
<?php
session_start ();
header ( "content-type:image/png" );
$width = 100;
$height = 30;
$im = imagecreate ( $width, $height );
imagecolorallocate ( $im, 255, 200, 200 );
for($i=0;$i<4;$i++) {
$num =dechex(rand ( 0, 15 ));
}
@$_SESSION [check] = $num;
for($i = 0; $i < strlen( @$_SESSION [check] ); $i ++) {
$font = mt_rand ( 3, 5 );
$x = mt_rand ( 1, 8 )+$width*$i/4;
$y = mt_rand ( 1, $height / 4 );
$string = @$_SESSION [check];
$color = imagecolorallocate ( $im, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
imagestring ( $im, $font, $x, $y, $string, $color );
}
imagepng ( $im );
imagedestroy($im);