麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > 建站經(jīng)驗(yàn) > 正文

php實(shí)現(xiàn)的數(shù)字驗(yàn)證碼及數(shù)字運(yùn)算驗(yàn)證碼

2024-04-25 20:40:25
字體:
供稿:網(wǎng)友

本文實(shí)例講述了php實(shí)現(xiàn)的數(shù)字驗(yàn)證碼及數(shù)字運(yùn)算驗(yàn)證碼。分享給大家供大家參考。具體如下:

1. 數(shù)字驗(yàn)證碼:

<?php

//第一個實(shí)例是數(shù)字驗(yàn)證碼,最常見的驗(yàn)證碼。多少個數(shù)字可以由自己決定。

//$num是生成的驗(yàn)證碼包含幾個數(shù)字

getValidate(4,60,20);

function getValidate($num,$w,$h){

$code = "";

for($i=0;$i<$num;$i++){

$code .= rand(0,9);

}

//code變量最后是$num個數(shù)字,并且是字符串。因襲如果是生成四位的數(shù)字驗(yàn)證碼,可以用rand(1000,9999)生成

Header("Content-type:image/PNG");

$img = imagecreate($w,$h);//創(chuàng)建圖片,長寬參數(shù)是一開始定義好的。

$black = imagecolorallocate($img,0,0,0);//定義黑色

$gray = imagecolorallocate($img,200,200,200);//定義灰色

$bgcolor = imagecolorallocate($img,255,255,255);//背景色白色

imagefill($img,0,0,$gray);

//imagefill($image,ing $x,int $y,int $color),在image圖像的坐標(biāo)x,y處用color顏色執(zhí)行區(qū)域填充

//給驗(yàn)證碼畫上邊框,感覺驗(yàn)證碼美美的,其實(shí)呢畫邊框就是給他畫上一個矩形

imagerectangle($img,0,0,$w-1,$h-1,$black);//用黑色的框框

/*imagestring($image,$font,$x,$y,$s,$col)

用col顏色將字符串s畫到image所代表的圖像的x,y處(xy是字符串的左上角坐標(biāo)),

整幅圖像的左上角為(0,0)如果font是1,2,3,4,5則使用內(nèi)置字體*/

//一下是畫四個數(shù)字的方法,讓四個字符位置都隨機(jī)等

$strx = rand(5,10);

for($i = 0;$i < $num;$i++){

$strops = rand(1,6);

imagestring($img,5,$strx,$strops,substr($code,$i,1),$black);

$strx += rand(8,12);

//strx是橫坐標(biāo),需要每一次加上之前的坐標(biāo),保證不會重疊。縱坐標(biāo)不管

}

//substr() 函數(shù)返回字符串的一部分,substr(string,start,length),要截取的字符串,start開始位置,length截取的長度

//生成好了數(shù)字,下面要給驗(yàn)證碼區(qū)域一些干擾,防止一些工具可以自動識別

//1.方法一:給背景加上很多噪點(diǎn)

//imagesetpixel($image,$x,$y,$color),在image圖像中用color顏色在x,y坐標(biāo)(圖像左上角為0,0)上畫一個點(diǎn)

for($i = 0;$i<80;$i++){

imagesetpixel($img, rand(0,$w), rand(0,$h), $black);//這些點(diǎn)分布在這個背景里面

}

//2.方法二:繪制幾條虛線

$style = array($black,$gray);

imagesetstyle($img, $style);

//imagesetstyle($image,$style),設(shè)定畫線的風(fēng)格,像素組成的數(shù)組

$y1 = rand(0,$h);

$y2 = rand(0,$h);

$y3 = rand(0,$h);

$y4 = rand(0,$h);

imageline($img,0,$y1,$w,$y2,IMG_COLOR_STYLED);

imageline($img,0,$y3,$w,$y4,IMG_COLOR_STYLED);

imagepng($img);

imagedestroy($img);

}

?>

2. 數(shù)字運(yùn)算驗(yà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;

}

}

?>

希望本文所述對大家的php程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 视频一区二区三区免费观看 | 国产精品久久久久国产精品三级 | 亚洲欧美国产精品va在线观看 | 在线观看一区二区三区四区 | 欧美成人免费电影 | 色污视频 | 国产亚色| 欧美伦交| 久久9色 | 黄色大片免费网站 | 法国性hdfreexxxx人妖 | 欧美日韩国产成人在线观看 | 91精品国产777在线观看 | 国产美女爽到喷白浆的 | 美女毛片儿 | 日本成人高清视频 | 黄色片免费看网站 | 国产999在线| 色视频在线 | 精品国产一区二区三区四区阿崩 | 久久久久久中文字幕 | 爽毛片| 九九热精品视频在线 | 加勒比综合 | 欧美高清第一页 | 懂色av懂色aⅴ精彩av | 欧美a久久 | 国产精品久久久久久久久久大牛 | 欧美成人福利 | 国产1区2区3区中文字幕 | 免费在线看黄 | 欧美1区2区在线观看 | 伊人亚洲精品 | 午夜精品网站 | 色妹子久久 | 国产免费一区视频 | 天天鲁在线视频免费观看 | 一区二区三区在线观看免费 | 国内一区 | 色呦呦一区二区三区 | 国产精品久久久久久久久久尿 |