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

首頁 > 開發(fā) > PHP > 正文

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

2024-05-04 23:38:23
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php實現(xiàn)的數(shù)字驗證碼及數(shù)字運算驗證碼,以實例形式分別描述了php實現(xiàn)數(shù)字驗證碼及數(shù)學(xué)運算驗證碼的相關(guān)技巧,非常簡單實用,需要的朋友可以參考下

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

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

 

 
  1. <?php 
  2. //第一個實例是數(shù)字驗證碼,最常見的驗證碼。多少個數(shù)字可以由自己決定。 
  3. //$num是生成的驗證碼包含幾個數(shù)字 
  4. getValidate(4,60,20); 
  5. function getValidate($num,$w,$h){ 
  6. $code = ""
  7. for($i=0;$i<$num;$i++){ 
  8. $code .= rand(0,9); 
  9. //code變量最后是$num個數(shù)字,并且是字符串。因襲如果是生成四位的數(shù)字驗證碼,可以用rand(1000,9999)生成 
  10. Header("Content-type:image/PNG"); 
  11. $img = imagecreate($w,$h);//創(chuàng)建圖片,長寬參數(shù)是一開始定義好的。 
  12. $black = imagecolorallocate($img,0,0,0);//定義黑色 
  13. $gray = imagecolorallocate($img,200,200,200);//定義灰色 
  14. $bgcolor = imagecolorallocate($img,255,255,255);//背景色白色 
  15. imagefill($img,0,0,$gray); 
  16. //imagefill($image,ing $x,int $y,int $color),在image圖像的坐標(biāo)x,y處用color顏色執(zhí)行區(qū)域填充 
  17. //給驗證碼畫上邊框,感覺驗證碼美美的,其實呢畫邊框就是給他畫上一個矩形 
  18. imagerectangle($img,0,0,$w-1,$h-1,$black);//用黑色的框框 
  19. /*imagestring($image,$font,$x,$y,$s,$col) 
  20. 用col顏色將字符串s畫到image所代表的圖像的x,y處(xy是字符串的左上角坐標(biāo)), 
  21. 整幅圖像的左上角為(0,0)如果font是1,2,3,4,5則使用內(nèi)置字體*/ 
  22. //一下是畫四個數(shù)字的方法,讓四個字符位置都隨機等 
  23. $strx = rand(5,10); 
  24. for($i = 0;$i < $num;$i++){ 
  25. $strops = rand(1,6); 
  26. imagestring($img,5,$strx,$strops,substr($code,$i,1),$black); 
  27. $strx += rand(8,12); 
  28. //strx是橫坐標(biāo),需要每一次加上之前的坐標(biāo),保證不會重疊。縱坐標(biāo)不管 
  29. //substr() 函數(shù)返回字符串的一部分,substr(string,start,length),要截取的字符串,start開始位置,length截取的長度 
  30. //生成好了數(shù)字,下面要給驗證碼區(qū)域一些干擾,防止一些工具可以自動識別 
  31. //1.方法一:給背景加上很多噪點 
  32. //imagesetpixel($image,$x,$y,$color),在image圖像中用color顏色在x,y坐標(biāo)(圖像左上角為0,0)上畫一個點 
  33. for($i = 0;$i<80;$i++){ 
  34. imagesetpixel($img, rand(0,$w), rand(0,$h), $black);//這些點分布在這個背景里面 
  35. //2.方法二:繪制幾條虛線 
  36. $style = array($black,$gray); 
  37. imagesetstyle($img, $style); 
  38. //imagesetstyle($image,$style),設(shè)定畫線的風(fēng)格,像素組成的數(shù)組 
  39. $y1 = rand(0,$h); 
  40. $y2 = rand(0,$h); 
  41. $y3 = rand(0,$h); 
  42. $y4 = rand(0,$h); 
  43. imageline($img,0,$y1,$w,$y2,IMG_COLOR_STYLED); 
  44. imageline($img,0,$y3,$w,$y4,IMG_COLOR_STYLED); 
  45. imagepng($img); 
  46. imagedestroy($img); 
  47. ?> 

2. 數(shù)字運算驗證碼:

 

 
  1. <?php 
  2. getValidate(100,30); 
  3. function getValidate($w,$h){ 
  4. $img = imagecreate($w,$h); 
  5. $gray = imagecolorallocate($img,255,255,255); 
  6. $black = imagecolorallocate($img,rand(0,200),rand(0,200),rand(0,200)); 
  7. $red = imagecolorallocate($img, 255, 0, 0); 
  8. $white = imagecolorallocate($img, 255, 255, 255); 
  9. $green = imagecolorallocate($img, 0, 255, 0); 
  10. $blue = imagecolorallocate($img, 0, 0, 255); 
  11. imagefilledrectangle($img, 0, 0, 100, 30, $black); 
  12. for($i = 0;$i < 80;$i++){ 
  13. imagesetpixel($img, rand(0,$w), rand(0,$h), $gray); 
  14. $num1 = rand(1,99); 
  15. $num2 = rand(1,99); 
  16. imagestring($img, 5, 5, rand(1,10), $num1, $red); 
  17. imagestring($img,5,30,rand(1,10),getRand(), $white); 
  18. imagestring($img,5,45,rand(1,10),$num2, $green); 
  19. imagestring($img,5,65,rand(1,10),"=", $blue); 
  20. imagestring($img,5,80,rand(1,10),"?", $red); 
  21. header("content-type:image/png"); 
  22. imagepng($img); 
  23. imagedestroy($img); 
  24. function getRand(){ 
  25. $code = rand(0,1); 
  26. switch ($code) { 
  27. case 0: 
  28. return "+"
  29. break
  30. case 1: 
  31. return "-"
  32. break
  33. default
  34. # code... 
  35. break
  36. ?> 

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: aa级黄色片 | 欧美黄色片一级 | 亚洲va久久久噜噜噜久久男同 | av噜噜在线| 成人午夜淫片a | 久久免费观看一级毛片 | 国产在线91 | 手机在线看片国产 | 日本黄色一级电影 | 黄色av.com| 最新中文字幕第一页视频 | 国产女做a爱免费视频 | 久久精品一区二区三区不卡牛牛 | 极品五月天 | 国产精品自拍片 | 成人视屏网站 | 最新欧美精品一区二区三区 | 毛片成人| 中文字幕网站在线 | 久久精品视频69 | 国产精品成人亚洲一区二区 | 亚洲一区二区三区精品在线观看 | 久久久久久中文字幕 | 成人在线视频黄色 | 法国极品成人h版 | 成年免费看 | 成人做爰www免费看 欧美精品免费一区二区三区 | 色诱亚洲精品久久久久久 | 国产精品av久久久久久久久久 | 神马久久蜜桃 | 免费国产网站 | 欧洲精品色 | 性高湖久久久久久久久aaaaa | 男女无套免费视频 | 一级黄色淫片 | 性爱视频免费 | 在线中文字幕观看 | 二区三区在线观看 | 国产日韩在线观看一区 | 免费一级欧美 | 免费在线观看成人av |