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

PHP实现变色验证码实例_php技巧

php 搞代码 4年前 (2022-01-26) 28次浏览 已收录 0个评论
 <BR><?php <BR>header("Content-type: image/png,charset='utf-8'"); <BR>$im = imagecreatetruecolor(400, 30); <BR>//白色 <BR>$white = imagecolorallocate($im, 255, 255, 255); <BR>//红色 <BR>$red = imagecolorallocate($im, 255, 0, 0); <BR>//黑色 <BR>$black=imagecolorallocate($im, 0, 0, 0); <BR>//绿色 <BR>$green=imagecolorallocate($im, 0, 255, 0); <BR>//蓝色 <BR>$blue=imagecolorallocate($im, 0, 0, 255); <BR>$color_arr=array($green,$blue,$red); <BR>$color=array_rand($color_arr); <BR>$text = '我靠这验证码太变态啦'; <BR>$textlen=iconv_strlen($text,'utf-8');//计算字符串长度 <BR>//随机截取两个字符,变色显示 <BR>$p1=rand(1,$textlen)-1; <BR>while(($p2=rand(1,$textlen)-1)==$p1); <BR>$w1=iconv_substr($text,$p1,1,'utf-8'); <BR>$w2=iconv_substr($text,$p1,1,'utf-8'); <BR>//字体文件 (PS:T不错的php Q扣峮:276167802,验证:csl) <BR>$font = 'simkai.ttf'; <BR>imagefilledrectangle($im, 0, 0, 399, 29, $white); <BR>for($i=0;$i<$textlen;$i++) <BR>{ <BR>if($i==$p1||$i==$p2) <BR>{ <BR>imagettftext($im, 15, 0, 20*($i-1)+20, 20, $color_arr[$color], $font, iconv_substr($text<div style="color:transparent">本文来源gaodai.ma#com搞##代!^码@网*</div><pre>搞gaodaima代码

,$i,1,’utf-8′));
}
else
{
imagettftext($im, 15, 0, 20*($i-1)+20, 20, $black, $font, iconv_substr($text,$i,1,’utf-8′));
}
}
imagepng($im);
imagedestroy($im);
?>

验证码中的字符并不是同一种颜色,让用户输入指定颜色的验证码,这样安全性会更好的。


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

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

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

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