一个简单的纯php验证码
<?php
$char=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"0","2","3","4","5","6","7","8","9","1" );
$text=array_rand($char,5); //随即获取字符
//定义画布和颜色
$image=imageCreate(200,60);
$bg=imageColorAllocate($image,237,247,255);
$rect_border=imageColorAllocate($image,255,238,251);
$textColor=imageColorAllocate($image,142,203,241);
$tstyle=array
(
"imageChar",
"imageCharUp"
);
//画框和背景填充
imageSetThickness($image,2);
imageRectangle($image,0,0,303,103,$rect_border);
//画出字符
for($i=0;$i<count($text);$i++)
{
//随即获取画出文字的格式
$textstyle=array_rand($tstyle,1);
if($i==0)
{
$tstyle[$textstyle]($image,5,40,30,$char[$text[$i]],$textColor);
}
else
{
$tstyle[$textstyle]($image,5,($i+2)*20,30,$char[$text[$i]],$textColor);
}
}
header("Content-type:image/png");
imagepng($image);
?>
浙公网安备 33010602011771号