php數(shù)字運(yùn)算驗(yàn)證碼的實(shí)現(xiàn)代碼
本文實(shí)例講述了php實(shí)現(xiàn)數(shù)字運(yùn)算驗(yàn)證碼的方法,具體實(shí)現(xiàn)方法如下:
<?php
getValidate(100,30);
function getValidate($w,$h){
$img = imagecreate($w,$h);
$gray = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200));
$red = imagecolorallocate($img, 255, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
imagefilledrectangle($img, 0, 0, 100, 30, $black);
for($i = 0;$i < 80;$i++){
imagesetpixel($img, rand(0,$w), rand(0,$h), $gray);
}
$num1 = rand(1,99);
$num2 = rand(1,99);
imagestring($img, 5, 5, rand(1,10), $num1, $red);
imagestring($img,5,30,rand(1,10),getRand(), $white);
imagestring($img,5,45,rand(1,10),$num2, $green);
imagestring($img,5,65,rand(1,10),"=", $blue);
imagestring($img,5,80,rand(1,10),"?", $red);
header("content-type:image/png");
imagepng($img);
imagedestroy($img);
}
function getRand(){
$code = rand(0,1);
switch ($code) {
case 0:
return "+";
break;
case 1:
return "-";
break;
default:
# code...
break;
}
}
?>
實(shí)現(xiàn)效果:

以上介紹的就是使用php實(shí)現(xiàn)數(shù)字運(yùn)算驗(yàn)證碼的方法,希望對大家的學(xué)習(xí)有所幫助。
- php 判斷是否是中文/英文/數(shù)字示例代碼
- PHP的幾個(gè)常用數(shù)字判斷函數(shù)代碼
- php判斷輸入是否是純數(shù)字,英文,漢字的方法
- php中數(shù)字、字符與對象判斷函數(shù)用法實(shí)例
- 利用PHP判斷是否是連乘數(shù)字串的方法示例
- PHP正則匹配中英文、數(shù)字及下劃線的方法【用戶名驗(yàn)證】
- PHP寫的簡單數(shù)字驗(yàn)證碼實(shí)例
- php生成4位數(shù)字驗(yàn)證碼的實(shí)現(xiàn)代碼
- php實(shí)現(xiàn)的數(shù)字驗(yàn)證碼及數(shù)字運(yùn)算驗(yàn)證碼
- php生成數(shù)字字母的驗(yàn)證碼圖片
- 支持中文、字母、數(shù)字的PHP驗(yàn)證碼
- 支持中文字母數(shù)字、自定義字體php驗(yàn)證碼代碼
- php中文字母數(shù)字驗(yàn)證碼實(shí)現(xiàn)代碼
- php用正則判斷是否為數(shù)字的方法
相關(guān)文章
php筆記之:php函數(shù)range() round()和list()的使用說明
本篇文章介紹了,php函數(shù)range() round()和list()的使用說明。需要的朋友參考下2013-04-04
thinkPHP3.2簡單實(shí)現(xiàn)文件上傳的方法
這篇文章主要介紹了thinkPHP3.2簡單實(shí)現(xiàn)文件上傳的方法,重點(diǎn)介紹了thinkPHP實(shí)現(xiàn)文件上傳功能的控制器文件相關(guān)技巧,需要的朋友可以參考下2016-05-05
PHP 計(jì)算兩個(gè)特別大的整數(shù)實(shí)例代碼
這篇文章主要介紹了PHP 計(jì)算兩個(gè)特別大的整數(shù)實(shí)例代碼,需要的朋友可以參考下2018-05-05
ThinkPHP做文字水印時(shí)提示call an undefined function exif_imagetype()解
這篇文章主要介紹了ThinkPHP做文字水印時(shí)提示call an undefined function exif_imagetype()解決方法,是項(xiàng)目開發(fā)中非常實(shí)用的技巧,需要的朋友可以參考下2014-10-10
thinkPHP框架中l(wèi)ayer.js的封裝與使用方法示例
這篇文章主要介紹了thinkPHP框架中l(wèi)ayer.js的封裝與使用方法,結(jié)合實(shí)例形式分析了thinkPHP中調(diào)用layer.js的具體操作技巧與注意事項(xiàng),需要的朋友可以參考下2019-01-01

