Allen's Blog
      Home  [登入

    關於本站
本站內容:   JavaScript 應用  || PHP 範例  || 好好過日子  || 思想理論  || 人生過往  || 剪貼圖像
站外連結:Never Stop  || 我的相簿  || MyTube  || 數字看台灣

 


[Run] 如何以 PHP 產生驗證碼  2022-05-15 11:37:13 - 點閱 93   ( PHP 範例 )

$fname="temp/".date("YmdHis").rand(0,9).rand(0,9).".png";

$im = imagecreatetruecolor(78, 26);//show area
$white = imagecolorallocate($im, intval(rand(220,255)),intval(rand(220,255)),intval(rand(220,255)));
imagefilledrectangle($im, 0, 0, 399, 29, $white);

$font = 'func/trebuc.ttf'; //字形檔
$sp=-10;//start point of each code

$color = imagecolorallocate($im, rand(200,255), rand(200,255), rand(200,255));
imagefilledellipse ($im, rand(0,76), rand(0,26), 78, 26, $color);//change back ground

for ($i=0;$i<4;$i++) {
$n=mt_rand(1,10);
if ($n==1){$psd="1";}elseif ($n==2){$psd="2";}elseif ($n==3){$psd="3";}
elseif ($n==4){$psd="4";}elseif ($n==5){$psd="5";}elseif ($n==6){$psd="6";}
elseif ($n==7){$psd="8";}elseif ($n==8){$psd="8";}elseif ($n==9){$psd="9";}
elseif ($n==10){$psd="0";}

$text = $psd;
$sp = $sp+17;
$size = rand(16,22);
$position = rand(20,24);
$angle=rand(-30,30);
$color = imagecolorallocate($im, rand(0,200), rand(0,200), rand(0,200));
$color2 = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));

$vague = 1;
imagettftext($im, $size, $angle, $sp, $position, $color, $font, $text);
imagettftext($im, $size, $angle+$vague, $sp+$vague, $position+$vague, $color2, $font, $text);//make each code vagueimageline($image,$x0, $y0 + $radius,$x1, $y1 + $radius,$color);
    imageline($im,0, rand(0,26),76, rand(0,26),$color2);
}


imagepng($im,$fname);
ImageDestroy($im);

$exebody="<br><table width=100% border=0><tr><td align=center>";
$exebody.= "<br>";
$exebody.= "<img border=2 src='".$fname."'>";
$exebody.= "<br></td></tr></table>";