验证码

来源:互联网 发布:究极风暴4卡顿优化补丁 编辑:程序博客网 时间:2024/05/09 16:20
<?php
session_start();
function random($len=4) {
    $srcstr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    mt_srand();
    $str="";
    for($i=0;$i<$len;$i++) {
        $str.=$srcstr[mt_rand(0,61)];
    }
    return $str;
}
$str=random(4);
$_SESSION['_register_rand_number'] = strtoupper($str);
function genimg($str,$width=150,$height=30) {
    $im=imagecreate($width,$height);
    //背景色
    $back=imagecolorallocate($im,0xFF,0xFF,0xFF);
    //模糊点颜色
    $pix=imagecolorallocate($im,0x68,0x80,0x38);
    //字体色
    $font=imagecolorallocate($im,0,0,0);
    //绘模糊作用的点
    mt_srand();
    for($i=0;$i<1000;$i++) {
        imagesetpixel($im,mt_rand(0,$width),mt_rand(0,$height),$pix);
    }
    //写字,选择ComicSansMS字体
    imagettftext($im,24,0,10,25,$font,"comic.ttf",$str);
    //imagestring($im,5,3,3,$str,$font);
    imagerectangle($im,0,0,$width-1,$height-1,$font);
    header("Content-Type:image/png");
    imagepng($im);
    imagedestroy($im);
}
genimg($str,90,30);
?>


<?php
session_start();
echo $_SESSION['_register_rand_number'];
?>
 
原创粉丝点击