• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP自定义大小验证码的方法详解_php技巧

php 搞代码 3年前 (2022-01-26) 27次浏览 已收录 0个评论
<?php<BR>function vCode($num=4,$size=20, $width=0,$height=0){ <BR>        !$width && $width = $num*$size*4/5+5<span>%本文来源gaodai#ma#com搞*代#码9网#</span><strong>搞gaodaima代码</strong>; <BR>        !$height && $height = $size + 10; <BR>        // 去掉了 0 1 O l 等 <BR>            $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW"; <BR>            $code = ''; <BR>            for ($i=0; $i<$num; $i++){ <BR>                    $code.= $str[mt_rand(0, strlen($str)-1)]; <BR>            } <BR>            // 画图像 <BR>            $im = imagecreatetruecolor($width,$height); <BR>            // 定义要用到的颜色 <BR>            $back_color = imagecolorallocate($im, 235, 236, 237); <BR>            $boer_color = imagecolorallocate($im, 118, 151, 199); <BR>            $text_color = imagecolorallocate($im, mt_rand(0,200), mt_rand(0,120), mt_rand(0,120)); <br><br>            // 画背景 <BR>        imagefilledrectangle($im,0,0,$width,$height,$back_color); <BR>            // 画边框 <BR>            imagerectangle($im,0,0,$width-1,$height-1,$boer_color); <BR>            // 画干扰线 <BR>            for($i=0;$i<5;$i++){ <BR>                    $font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); <BR>                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); <BR>                } <BR>        // 画干扰点 <BR>        for($i=0;$i<50;$i++){ <BR>                $font_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); <BR>                imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$font_color); <BR>        } <BR>        // 画验证码 <BR>        @imagefttext($im, $size , 0, 5, $size+3, $text_color, 'c://WINDOWS//Fonts//simsun.ttc',$code); <BR>        header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate"); <BR>        header("Content-type: image/png"); <BR>        imagepng($im); <BR>        imagedestroy($im); <BR>} <BR>?><BR>


函数描述及例子:
<?
// 4个字符,大小为20
vCode(4,20);
?>


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP自定义大小验证码的方法详解_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址