电脑安全

您当前的位置:主页 > 电脑安全 >

php 生成中文验证码程序-网络编程

来源:[db:来源]标题:   图片    编辑:电脑技术全能网 时间:2019-09-20 18:32

原标题:php 生成中文验证码程序-网络编程
   明天有意中想起写考证码数字加汉字,上面是代码比拟轻易没甚么好说先来看看后果图吧.还不错吧?<?phpHeader("Content-type: image/PNG");//天生图片的范例$str = "的一是在了和睦有大这主中人蚕亿矩";//随意回的你能够本人增添$Width = 240;//图片高度$imgHeight = 40;//图片宽度$C_img = imagecreate($Width,$imgHeight);$bgColor = ImageColorAllocate($C_img,255,255,255);$f_font = "heiti.ttf";//这里能够抉择别的的字体$white=imagecolorallocate($C_img,234,185,95);imagearc($C_img, 150, 8, 20, 20, 75, 170, $white);imagearc($C_img, 180, 7,50, 30, 75, 175, $white);imageline($C_img,20,20,180,30,$white);imageline($C_img,20,18,170,50,$white);imageline($C_img,25,50,80,50,$white);$noise_num = 800;//杂点的数据$line_num = 20;//线条的数目imagecolorallocate($C_img,0xff,0xff,0xff);$rectangle_color=imagecolorallocate($C_img,0xAA,0xAA,0xAA);$noise_color=imagecolorallocate($C_img,0x00,0x00,0x00);$font_color=imagecolorallocate($C_img,0x00,0x00,0x00);$line_color=imagecolorallocate($C_img,0x00,0x00,0x00);for($i=0;$i<$noise_num;$i++){imagesetpixel($C_img,mt_rand(0,$Width),mt_rand(0,$imgHeight),$noise_color);}for($i=0;$i<$line_num;$i++){imageline($C_img,mt_rand(0,$Width),mt_rand(0,$imgHeight),mt_rand(0,$Width),mt_rand(0,$imgHeight),$line_color);}$randnum=rand(0,strlen($str)-4);if($randnum%2)$randnum+=1;$str = substr($str,$randnum,8);$str = iconv("GB2312","UTF-8",$str).rand(0,1000);//转换编码ImageTTFText($C_img, 20, 0, 16, 30, $font_color, $f_font, $str);ImagePNG($C_img);ImageDestroy($C_img);?>说明:转载请阐明原处www.dnjishu.com