手机版

PHP验证码函数代码(简单实用)

时间:2021-11-16 来源:互联网 编辑:宝哥软件园 浏览:

效果图

复制代码代码如下:php /** * vCode(m,n,x,y) m个数字显示大小为n边宽x边高y * micxp * JB 51。net */session _ start();vCode(4,15);//4个数字,显示大小为15函数vCode($num=4,$size=20,$width=0,$height=0) {!$ width $ width=$ num * $ size * 4/5 5;$ height $ height=$ size 10//去掉了0 1 0 1等$ str=' 23456789 abcdefghijkmnpqrstuvwxyzabbdefghijklmnpqrstuvw ';$ code=for($ I=0;$ i $ num$i ) { $code .=$str[mt_rand(0,strlen($ str)-1)];} //画图像$ im=imagecreatetrue color($ width,$ height);//定义要用到的颜色$ back _ color=image color allocate($ im,235,236,237);$ Boer _ color=image color allocate($ im,118,151,199);$ text _ color=image color allocate($ im,mt_rand(0,200),mt_rand(0,120),mt_rand(0,120));//画背景imagefiledrectangle($ im,0,0,$width,$height,$ back _ color);//画边框imagerectangle($im,0,0,$width-1,$height-1,$ Boer _ color);//画干扰线对于($ I=0;$ I 5;$ I){ $ font _ color=image color allocate($ im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));imagearc($im,mt_rand(- $width,$width),mt_rand(- $height,$height),mt_rand(30,$width * 2),mt_rand(20,$height * 2),mt_rand(0,360),mt_rand(0,360),$ font _ color);} //画干扰点对于($ I=0;$ I 50 $ I){ $ font _ color=image color allocate($ im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$ font _ color);} //画验证码@imagefttext($im,$size,0,5,$size,3,$text_color,' c : \ \ WINDOWs \ \ Fonts \ \ simsun。TTC ',$ code);$ _ SESSION[' verifYCOde ']=$ COde;标头('缓存-控制:最大年龄=1,s-最大年龄=1,无缓存,必须重新验证');标题('内容类型:图像/png;charset=GB 2312’);图像png($ im);图像销毁($ im);} ?

版权声明:PHP验证码函数代码(简单实用)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。