《PHP實(shí)例:php實(shí)現(xiàn)漢字驗(yàn)證碼和算式驗(yàn)證碼的方法》要點(diǎn):
本文介紹了PHP實(shí)例:php實(shí)現(xiàn)漢字驗(yàn)證碼和算式驗(yàn)證碼的方法,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
本文實(shí)例講述了php實(shí)現(xiàn)漢字驗(yàn)證碼和算式驗(yàn)證碼的辦法.分享給大家供大家參考.具體分析如下:PHP編程
年夜家知道簡(jiǎn)單數(shù)字或者字母驗(yàn)證碼很容易被破解,但是算式驗(yàn)證碼或者中文漢字驗(yàn)證碼不容易被破解,
所以建議年夜家在使用驗(yàn)證碼的時(shí)候,盡量用算式驗(yàn)證碼或者中文漢字驗(yàn)證碼.
下面是我寫(xiě)的兩種驗(yàn)證碼代碼,有用到的朋友可以參考下:PHP編程
1.算式驗(yàn)證碼:
PHP編程
代碼如下:
<?php
session_start();
header("Content-type: image/png");
$num1 = mt_rand(0,9);//第一位數(shù)
$num2 = mt_rand(1,9);//第二位數(shù)
$type_str = "+-*";//辦法字符串集合
$type = substr($type_str,rand(0,2),1);//隨機(jī)辦法
$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.中文漢字驗(yàn)證碼:PHP編程
代碼以下:
《PHP實(shí)例:php實(shí)現(xiàn)漢字驗(yàn)證碼和算式驗(yàn)證碼的方法》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP實(shí)例:php實(shí)現(xiàn)漢字驗(yàn)證碼和算式驗(yàn)證碼的方法》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/11856.html