php 生成图片验证码 并表单验证

来源:互联网 发布:guava 并发编程 编辑:程序博客网 时间:2024/06/15 15:39
<?php //因为要把产生的验证码保存到session中,此处为session开始 session_start(); //创建一张宽100高30的图像 $image = imagecreatetruecolor(100, 30); //为$image设置背景颜色为白色 $bgcolor = imagecolorallocate($image, 255, 255, 255); //填充背景颜色 imagefill($image, 0, 0, $bgcolor); //生成4个随机数 /* for($i=0; $i<4 i="" 6="" fontsize="6;" rand="" rgb="" 0="" 120="" fontcolor="imagecolorallocate($image," rand="" 0="" 120="" rand="" 0="" 120="" rand="" 0="" 120="" fontcontent="rand(0," 9="" x-="">left y->top $x=($i*100/4)+rand(5, 10); $y=rand(5, 10); imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor); } */ $captch_code=""; for($i=0; $i<4 i="" fontsize="6;" fontcolor="imagecolorallocate($image," rand="" 0="" 120="" rand="" 0="" 120="" rand="" 0="" 120="" data="1234567890abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ" data="" fontcontent="substr($data," rand="" 0="" strlen="" data="" 1="" captch_code="" fontcontent="" x-="">left y->top $x=($i*100/4)+rand(5, 10); $y=rand(5, 10); //此函数用来将产生的字符在背景图上画出来 imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor); } $_SESSION['authcode']=$captch_code;//把产生的验证码存入session中 //用来在背景图片上产生200个干扰点 for($i=0; $i<200; $i++){ //干扰点的颜色 $pointcolor=imagecolorallocate($image, rand(50,200), rand(50, 200), rand(50, 200)); //该函数用来把每个干扰点在背景上描绘出来 imagesetpixel( $image, rand(1, 99), rand(1,29), $pointcolor); } //产生三条干扰线 for ($i=0; $i <3 i="" code="" linecolor="imagecolorallocate($image," rand="" 80="" 220="" rand="" 80="" 220="" rand="" 80="" 220="" imageline="" image="" rand="" 1="" 99="" rand="" 1="" 29="" rand="" 1="" 99="" rand="" 1="" 29="" linecolor="" header="" png="" header="" content-type:image="" png="" imagepng="" image="" destory="" imagedestroy="" image=""> <?phpsession_start(); if(isset($_REQUEST['authcode'])){ // 将存在session里面的验证码全部小写化 $data_code = strtolower($_SESSION['authcode']); } ?>
原创粉丝点击