加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

生成验证码 随机干扰php实现

发布时间:2020-05-30 22:50:39 所属栏目:PHP 来源:互联网
导读:生成验证码 随机干扰php实现

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

<?php
session_start ();
header ( 'Content-type: image/png' );
//创建图片
$im = imagecreate($x=130,$y=45 );
$bg = imagecolorallocate($im,rand(50,200),rand(0,155),155)); //第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色
$fontColor = imageColorAllocate ( $im,255,255 );   //字体颜色
$fontstyle = 'rock.ttf';     //字体样式,这个可以从c:windowsFonts文件夹下找到,我把它放到和authcode.php文件同一个目录,这里可以替换其他的字体样式
//产生随机字符
for($i = 0; $i < 4; $i ++) {
	$randAsciiNumArray = array (rand(48,57),rand(65,90));
	$randAsciiNum = $randAsciiNumArray [rand ( 0,1 )];
	$randStr = chr ( $randAsciiNum );
	imagettftext($im,30,20)-rand(0,25),5+$i*30,rand(30,35),$fontColor,$fontstyle,$randStr);
	$authcode .= $randStr;
}
$_SESSION['authcode'] = $randFourStr;//用户和用户输入的验证码做比较

//干扰线
for ($i=0;$i<8;$i++){
	$lineColor        = imagecolorallocate($im,255),255));
	imageline ($im,$x),$y,$lineColor);
}

//干扰点
for ($i=0;$i<250;$i++){
	imagesetpixel($im,$y),$fontColor);
}
imagepng($im);
imagedestroy($im);
?>

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读