Heim  >  Artikel  >  php教程  >  php 中英文验证码程序

php 中英文验证码程序

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:php addslashes处理$_POST $_GET数组函数Nächster Artikel:php addslashes