圖形驗證功能我想在許多地方都用的上
只要是需要防止機器人連續作業的時候都是必要的
在此作個簡單的解說吧
以下為最重要產生圖片的的image.php

 //啟動SESSION
session_start ();
//設定亂數種子
mt_srand(microtime());
//srand ((double)microtime()*1000000000);

//設定產生幾個字
$fontLenth = 4;
//產生數字+英文的亂數字
$num = "";
for( $i = 0; $i $num .= dechex( rand( 1, 15 ) );
}

//設定SESSION給check.php做檢查
$_SESSION['img_num'] = $num;
//設定字體大小
$fontSize = 12;
//設定字型
$font = 'verdana.ttf';
//設定圖片寬
$picx = $fontSize * $fontLenth;
//設定圖片長
$picy = $fontSize*2;
//建立一個圖型
$im = imagecreate($picx, $picy);
//圖片背景為白色
$bg = imagecolorallocate($im, 255, 255, 255);
//文字顏色為藍色
$textcolor = imagecolorallocate($im, 0, 0, 255);
// 將文字放到圖片裡面
imagettftext($im, $fontSize,0, round($fontSize/3,0)+1, round($fontSize*4/3,0), $textcolor, $font, $num);
//輸出圖片
header("Content-type: image/png");
imagepng($im);
?>


可用產生驗證圖片

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 herb123456 的頭像
    herb123456

    PHP、MySQL、ExtJS、Linux、CentOS、Ubuntu

    herb123456 發表在 痞客邦 留言(1) 人氣()