天天看點

php驗證碼顯示亂碼,php 數字驗證碼怎麼總是出現亂碼啊?

你這直接就輸出了圖檔資料了,生成驗證碼的程式要另外儲存一個檔案。html中通過img标簽的src屬性值來引用該檔案

1.html

驗證碼:

php驗證碼顯示亂碼,php 數字驗證碼怎麼總是出現亂碼啊?

1.php

session_start();

srand((double)microtime()*1000000);

$im=imagecreate(45,18);

$black=imagecolorallocate($im,0,0,0);

$white=imagecolorallocate($im,255,255,255);

$gray=imagecolorallocate($im,200,200,200);

imagefill($im,0,0,$gray);

session_register("autonum");

$_SESSION["autonum"]="";

for($i=0;$i<4;$i++){

$str=mt_rand(1,3);

$size=mt_rand(3,6);

$authnum=mt_rand(0,9);

$_SESSION["autonum"].=$authnum;

imagestring($im,$size,(5+$i*10),$str,$authnum,imagecolorallocate($im,rand(0,130),rand(0,130),rand(0,130)));

}

for($i=0;$i<200;$i++){

$randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));

imagesetpixel($im,rand()%70,rand()%30,$randcolor);

}

imagepng($im);

imagedestroy($im);

?>

取消

評論