《PHP實例:php實現漢字驗證碼和算式驗證碼的方法》要點:
本文介紹了PHP實例:php實現漢字驗證碼和算式驗證碼的方法,希望對您有用。如果有疑問,可以聯系我們。
本文實例講述了php實現漢字驗證碼和算式驗證碼的辦法.分享給大家供大家參考.具體分析如下:PHP編程
年夜家知道簡單數字或者字母驗證碼很容易被破解,但是算式驗證碼或者中文漢字驗證碼不容易被破解,
所以建議年夜家在使用驗證碼的時候,盡量用算式驗證碼或者中文漢字驗證碼.
下面是我寫的兩種驗證碼代碼,有用到的朋友可以參考下:PHP編程
1.算式驗證碼:
PHP編程
代碼如下:
<?php
session_start();
header("Content-type: image/png");
$num1 = mt_rand(0,9);//第一位數
$num2 = mt_rand(1,9);//第二位數
$type_str = "+-*";//辦法字符串集合
$type = substr($type_str,rand(0,2),1);//隨機辦法
$change = mt_rand(1,3);
if($change==1){
?$code = "$num1$type$num2=?";
?$result = "\$verifyCode=$num1$type$num2;";
?eval($result);
?$_SESSION['authnum_session'] = $verifyCode;?
}elseif($change==2){
?$result = "\$verifyCode=$num1$type$num2;";
?eval($result);
??? $code = $num1.$type."_=".$verifyCode;
?$_SESSION['authnum_session'] = $num2;?
}elseif($change==3){
?$result = "\$verifyCode=$num1$type$num2;";
?eval($result);
??? $code = "_".$type.$num2."=".$verifyCode;
?$_SESSION['authnum_session'] = $num1;?
}
$im = imagecreate(68,28);??
$black = imagecolorallocate($im, 0,0,0);????
$white = imagecolorallocate($im, 255,255,255);
$gray = imagecolorallocate($im, 200,200,200);
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im,0,0,$white);???? ??
imagestring($im, 5, 10, 8, $code, $black);???
for($i=0;$i<70;$i++) {
?imagesetpixel($im, mt_rand(0, 58) , mt_rand(0, 28) , $black);
?imagesetpixel($im, mt_rand(0, 58) , mt_rand(0, 28) , $red);
?imagesetpixel($im, mt_rand(0, 58) , mt_rand(0, 28) , $gray);
}
imagepng($im);
imagedestroy($im);
?>
2.中文漢字驗證碼:PHP編程
代碼以下:
《PHP實例:php實現漢字驗證碼和算式驗證碼的方法》是否對您有啟發,歡迎查看更多與《PHP實例:php實現漢字驗證碼和算式驗證碼的方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.fzlkiss.com/jiaocheng/11856.html