Dies ist der Effekt, ohne die Sitzung zu ?ffnen (das Bild des Best?tigungscodes kann normal angezeigt werden)
Dies ist der Effekt nach dem ?ffnen der Sitzung (kein Bild angezeigt)
--------- - ------------------------------------------------- - ----------------
Entschuldigung, warum ist das so? --------------------
<?php session_start();
$width = 300; $height = 100 ;
$img = imagecreatetruecolor($width,$height);
$white = imagecolorallocate($img, 255, 255, 255);
$red = imagecolorallocate($img, 255, 0, 0);
imagefilledrectangle ($img, 0, 0, $width, $height, setColor($img));
function setColor($img)
{
return imagecolorallocate($img,getColor(),getColor(), getColor()); $b );
}
function getCode()
{
return $string = join('',array_rand(array_flip(array_merge(range(0,9),range('a','z') ,range ('A','Z'))),4));
}
$str = getCode();
$_SESSION['verifycode'] = $str;
for($i= 0; $i<4;$i++)
{
$size = setNum(20,50);
$angle = setNum(-15,15);
$x = ($width/4)* $i +mt_rand(1,9);
$y = mt_rand(($height/2),$height);
$color = setColor( $img );
$fontfile = './fonts/MSYH .ttf ';
$text = mb_substr(getCode(),$i,1,'utf-8');
imagettftext($img, $size, $angle, $x, $y, $color, $ Schriftartdatei, $text);
}
for($i=0;$i<1500;$i++)
{
imagesetpixel($img, mt_rand(0, $width), mt_rand(0, $height), setColor($img));
}
for($i=0;$i<3;$i++)
{
imageline($img, mt_rand(0, $width), mt_rand(0,$height), mt_rand(0, $ width), mt_rand(0,$height), setColor($img));
}
for($i=0;$i<3;$i++)
{
$cx = mt_rand(0, $width);
$cy = mt_rand(0, $height);
$width = mt_rand(0, $width/2);
$height = mt_rand(0, $height/2);
$start = mt_rand( 0, 360);
$end = mt_rand(0, 360);
$color = setColor($img);
imagearc($img, $cx, $cy, $width, $height, $start, $end, $color);
}
header('content-type:image/jpeg');
imagejpeg( $img );
imagedestroy( $img );
?>
應(yīng)該是會(huì)自動(dòng)刪除的吧?臨時(shí)文件.
另外你也可以考慮數(shù)據(jù)庫(kù)存儲(chǔ)session?啊?
我想你現(xiàn)在不是要處理已經(jīng)出錯(cuò)的問(wèn)題。建議你是先從,簡(jiǎn)單的圖片驗(yàn)證先做想。這個(gè)很有必要的。就是去除其它的無(wú)用代碼。已經(jīng)注冊(cè)及驗(yàn)證用戶密碼。單獨(dú)來(lái)試這個(gè)圖片SESSION的問(wèn)題。你要注冊(cè)是否需要隱藏域。