发布网友 发布时间:2022-04-06 04:22
共2个回答
热心网友 时间:2022-04-06 05:51
可以用php的GD库做
//随机生成验证码
class randomString
{
function createRandomStr($strLen)
{
list($usec, $sec) = explode(' ', microtime());
(float) $sec + ((float) $usec * 100000);
$number = '';
$number_len = $strLen;
$stuff = '12345670abcdefghijklmnopqrstuvwxyz';//附加码显示范围ABCDEFGHIJKLMNOPQRSTUVWXYZ
$stuff_len = strlen($stuff) - 1;
for ($i = 0; $i < $number_len; $i++) {
$number .= substr($stuff, mt_rand(0, $stuff_len), 1);
}
return $number;
}
}
通过ZD库将验证码变成图片
$number = $createStr->createRandomStr('4');//验证码的位数
$number_len = strlen($number);
$_SESSION["VERIFY_CODE"] = $number;
// 生成验证码图片
$img_width = 60;
$img_height = 20;
$img = imageCreate($img_width, $img_height);
ImageColorAllocate($img, 0x6C, 0x74, 0x70);
$white = ImageColorAllocate($img, 0xff, 0xff, 0xff);
$ix = 6;
$iy = 2;
for ($i = 0; $i < $number_len; $i++) {
imageString($img, 5, $ix, $iy, $number[$i], $white);
$ix += 14;
}
for($i=0;$i<200;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img, rand()%100 , rand()%50 , $randcolor);
}
// 输出图片
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));
imagepng($img);
imagedestroy($img);
热心网友 时间:2022-04-06 07:09
这里有现成的,4种类型验证码呢
http://jingyan.baidu.com/article/d45ad1488e7aa569552b80f3.html