2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > php如何实现随机数字和字母验证码的代码

php如何实现随机数字和字母验证码的代码

时间:2020-08-30 17:54:42

相关推荐

php如何实现随机数字和字母验证码的代码

后端开发|php教程

随机数字,php如何实现

后端开发-php教程

php实现随机数字、字母的验证码

自动挣钱app源码,ubuntu 移动到ssd,小爬虫自动割管器,remove() php,红帽蜘蛛seolzw

可自定义生成验证码文字的大小、数量、干扰项等等,也可以自定义验证文字的字体。。。

商场网页源码,vscode输出没东西,swap安装ubuntu,改tomcat的版本,动态sqlite3链接库,腐竹爬虫,php构造函数重载,长沙seo服务费用,免费搭建贴吧系统网站,理财购买模板lzw

废话不多说,直接上代码:

源码卫士,vscode调试代码超时,ubuntu 如何使用,Tomcat外网映射端口,php7使用sqlite3,旧手机搭建爬虫服务器怎么弄,nginx php 原理,番禺seo优化网络推广,电脑 手机网站二合一源码,dede utf8 后台模板lzw

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_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_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_pixel;$i++){ imagesetpixel($this->_image,mt_rand(0,$this->_width),mt_rand(0,$this->_height),$this->_getRandColor()); } } private function _getLine(){ for($i=1;$i_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($length30){ return false; } $chars=array( a,,c,d,e,f,g,h,k,m, ,p,x,y,z, A,B,C,D,E,F,G,H,K,M,N,P,X,Y,, 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

fonts/simfang.ttf, //引入字体文件//snow=>50,pixel=>100,line=>10 );$captcha=new Captcha($config);$captcha->getCaptcha();?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。