素材牛VIP会员
PHP 生成图形验证码
 陌***人  分类:PHP代码  人气:291  回帖:0  发布于6年前 收藏
<?php
session_start();
// main
$vcodes = '';
//generate Number 4
srand((double) microtime() * 1000000);
for ($i = 0; $i < 4; $i++) {
    $vcodes .= rand(1, 9);
}
$_SESSION['eifr_checkvcode'] = $vcodes;
if (function_exists('imagecreate')) {
    //generate picture validation code
    Header("Content-type: image/PNG");
    $img = imagecreate(44, 18);
    $bg  = ImageColorAllocate($img, 245, 245, 245);
    imagefill($img, 0, 0, $bg); //background
      
    //generate Number 4
    for ($i = 0; $i < 4; $i++) {
        $font = ImageColorAllocate($img, rand(100, 255), rand(0, 100), rand(100, 255));
        $vnum = substr($vcodes, $i, 1);
        imagestring($img, 5, 2 + $i * 10, 1, $vnum, $font);
    }
    //add interference
    for ($i = 0; $i < 100; $i++) {
        $randcolor = ImageColorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
        imagesetpixel($img, rand() % 70, rand() % 30, $randcolor);
    }
    ImagePNG($img);
    ImageDestroy($img);
}
?>
 标签:暂无标签

讨论这个帖子(0)垃圾回帖将一律封号处理……

暂无回帖!
 文明上网,理性发言!   😉 阿里云幸运券,戳我领取