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

首頁 > 編程 > PHP > 正文

php如何實現隨機數字和字母驗證碼的代碼

2020-03-22 20:30:21
字體:
來源:轉載
供稿:網友
php實現隨機數字、字母的驗證碼

可自定義生成驗證碼文字的大小、數量、干擾項等等,也可以自定義驗證文字的字體。。。

廢話不多說,直接上代碼:

 ?phpClass Captcha{ private $_fontfile=  private $_size=36; private $_width=200; private $_height=100; private $_length=4; private $_image=null; private $_snow=0; private $_pixel=0; private $_line=0; html' target='_blank'>public function __construct($config=array()){ if(is_array($config) count($config) 0){ if(isset($config[ fontfile ]) is_file($config[ fontfile ]) is_readable($config[ fontfile ])){ $this- _fontfile=$config[ fontfile  }else{ return false; if(isset($config[ size ]) $config[ size ] 0){ $this- _size=(int)$config[ size  if(isset($config[ width ]) $config[ width ] 0){ $this- _width=(int)$config[ width  if(isset($config[ height ]) $config[ height ] 0){ $this- _height=(int)$config[ height  if(isset($config[ length ]) $config[ length ] 0){ $this- _length=(int)$config[ length  if(isset($config[ snow ]) $config[ snow ] 0){ $this- _snow=(int)$config[ snow  if(isset($config[ pixel ]) $config[ pixel ] 0){ $this- _pixel=(int)$config[ pixel  if(isset($config[ line ]) $config[ line ] 0){ $this- _line=(int)$config[ line  $this- _image=imagecreatetruecolor($this- _width,$this- _height); return $this- _image; else{ return false; public function getCaptcha(){ $white=imagecolorallocate($this- _image,255,255,255); imagefilledrectangle($this- _image,0,0,$this- _width,$this- _height,$white); $str=$this- _generateStr($this- _length); if(false===$str){ return false; $fontfile=$this- _fontfile; for($i=0;$i $this- _length;$i++){ $size=$this- _size; $angle=mt_rand(-30,30); $x=ceil($this- _width/$this- _length)*$i+mt_rand(5,10); $y=ceil($this- _height/1.5); $color=$this- _getRandColor(); //針對中文字符截取 //$text=mb_substr($str,$i,1, utf-8  $text=$str{$i}; imagettftext($this- _image, $size, $angle, $x, $y, $color, $fontfile, $text); if($this- _snow){ $this- _getSnow(); }else{ if($this- _pixel){ $this- _getPixel(); if($this- _line){ $this- _getLine(); header( content-type:image/png  imagepng($this- _image); imagedestroy($this- _image); return strtolower($str); private function _getSnow(){ for($i=1;$i =$this- _snow;$i++){ imagestring($this- _image,mt_rand(1,5),mt_rand(0,$this- _width),mt_rand(0,$this- _height), * ,$this- _getRandColor()); private function _getPixel(){ for($i=1;$i =$this- _pixel;$i++){ imagesetpixel($this- _image,mt_rand(0,$this- _width),mt_rand(0,$this- _height),$this- _getRandColor()); private function _getLine(){ for($i=1;$i =$this- _line;$i++){ imageline($this- _image,mt_rand(0,$this- _width),mt_rand(0,$this- _height),mt_rand(0,$this- _width),mt_rand(0,$this- _height),$this- _getRandColor()); private function _generateStr($length=4){ if($length 1 || $length 30){ return false; $chars=array( a , b , c , d , e , f , g , h , k , m , n , p , x , y , z , A , B , C , D , E , F , G , H , K , M , N , P , X , Y , Z , 1,2,3,4,5,6,7,8,9 $str=join( ,array_rand(array_flip($chars),$length)); return $str; private function _getRandColor(){ return imagecolorallocate($this- _image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));? 

2、testCaptcha.php

 ?phprequire_once classgd.class.php $config=array( fontfile = fonts/simfang.ttf , //引入字體文件// snow = 50, pixel = 100, line = 10$captcha=new Captcha($config);$captcha- getCaptcha();? 

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP !

相關推薦:

php如何重寫session的存儲機制

如何通過php來遍歷文件夾獲取圖片目錄名稱及文件名

以上就是php如何實現隨機數字和字母驗證碼的代碼的詳細內容,PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 91色综合综合热五月激情 | 久久伊人国产精品 | 九色com | 国产成人免费高清激情视频 | 欧美高清一级片 | 国产精品视频一区二区三区四区五区 | 污版视频在线观看 | 久草在线综合 | 国产精品免费久久久 | 久久亚洲春色中文字幕久久 | 一区二区美女视频 | 娇喘在线| 免费看日产一区二区三区 | 91香蕉国产亚洲一区二区三区 | 中国毛片在线观看 | 久久99亚洲精品久久99果 | 亚洲午夜免费 | 男女生羞羞视频网站在线观看 | 国产午夜精品久久久久 | 美女露100%无遮挡 | 中文字幕 在线观看 | 色网站在线免费观看 | 欧美成人一区二区三区 | 中国老女人一级毛片视频 | 亚洲成人第一页 | 成人福利在线观看 | 国产69精品久久久久99尤 | 精品国内视频 | 成人午夜在线免费 | 国产成人小视频在线观看 | 欧美扩阴视频 | 久久精品视频免费观看 | 国产精品久久久久久久午夜片 | hdhdhdhd19日本人 | 87成人免费看片 | 久久精品探花 | 九一免费国产 | 国产精品久久久久久久久久大牛 | 国产91九色在线播放 | 国内精品伊人久久 | 国产精品久久久久久久娇妻 |