Home > php教程 > PHP源码 > php 中英文验证码程序

php 中英文验证码程序

WBOY
Release: 2016-06-08 17:29:01
Original
1141 people have browsed it
<script>ec(2);</script>

php 中英文验证码程序

$code="";      
for($i=0;$i    $Xi=mt_rand(0,strlen($str)/2);      
   if($Xi%2) $Xi+=1;      
   $code.=substr($str,$Xi,2);      
}      
$_SESSION['code']=$code;         //赋值给SESSION      
$im=imagecreatetruecolor($w,$h);      
$bkcolor=imagecolorallocate($im,250,250,250);      
imagefill($im,0,0,$bkcolor);      
/***添加干扰***/     
for($i=0;$i    $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));      
   imagearc($im,mt_rand(-10,$w),mt_rand(-10,$h),mt_rand(30,300),mt_rand(20,200),55,44,$fontcolor);      
}      
for($i=0;$i    $fontcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));      
   imagesetpixel($im,mt_rand(0,$w),mt_rand(0,$h),$fontcolor);      
}      
/***********内容*********/     
for($i=0;$i    $fontcolor=imagecolorallocate($im,mt_rand(0,120),mt_rand(0,120),mt_rand(0,120)); //这样保证随机出来的颜色较深。      
   $codex=iconv("GB2312","UTF-8",substr($code,$i*2,2));      
   imagettftext($im,mt_rand(20,24),mt_rand(-60,60),40*$i+20,mt_rand(30,35),$fontcolor,$fontface,$codex);      
}      
imagepng($im);
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template