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

php 中英文验证码程序

WBOY
WBOYOriginal
2016-06-08 17:29:011079browse
<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);
?>

Statement:
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