您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

php 中文与英文验证码程序代码_PHP教程

2024/4/25 3:55:21发布5次查看
php教程 中文与英文验证码程序代码
//英文验证码相对简单,不要作hex处理,直接用色彩值就ok了。如果
session_start();
function rand_create()
{
    //通知浏览器将要输出png图片
    header(content-type: image/png);
    //准备好随机数发生器种子 
    srand((double)microtime()*1000000);
    //准备图片的相关参数  
    $im = imagecreate(62,22);
    $black = imagecolorallocate($im, 0,0,0);  //rgb黑色标识符
    $white = imagecolorallocate($im, 255,255,255); //rgb白色标识符
    $gray = imagecolorallocate($im, 200,200,200); //rgb灰色标识符
    //开始作图    
    imagefill($im,0,0,$gray);
    while(($randval=rand()%100000)        $_session[auth_code] = $randval;
        //将四位整数验证码绘入图片 
        imagestring($im, 5, 10, 3, $randval, $black);
    }
    //加入干扰象素   
    for($i=0;$i        $randcolor = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
        imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
    }
    //输出验证图片
    imagepng($im);
    //销毁图像标识符
    imagedestroy($im);
}
rand_create();
//调用方法
//中文验证码程序如下
header(content-type: image/png);
$str = 这里设置一中文如果中国web第一站www.bkjia.com;
$imagesw = 140;
$imagesh = 40;
//
$auimg = imagecreate($imagesw,$imagesh);
$bgc = imagecolorallocate($auimg,255,255,255);
$font = heiti.ttf;//这里设置字体,你可以随便下载一款字体哦。
$white=imagecolorallocate($auimg,234,185,95);
imagearc($auimg, 150, 8, 20, 20, 75, 170, $white);
imagearc($auimg, 180, 7,50, 30, 75, 175, $white);
imageline($auimg,20,20,180,30,$white);
imageline($auimg,20,18,170,50,$white);
imageline($auimg,25,50,80,50,$white);
$noise_num = 800;
$line_num = 20;
imagecolorallocate($auimg,0xff,0xff,0xff);
$rectangle_color=imagecolorallocate($auimg,0xaa,0xaa,0xaa);
$noise_color=imagecolorallocate($auimg,0x00,0x00,0x00);
$font_color=imagecolorallocate($auimg,0x00,0x00,0x00);
$line_color=imagecolorallocate($auimg,0x00,0x00,0x00);
for($i=0;$i imagesetpixel($auimg,mt_rand(0,$imagesw),mt_rand(0,$imagesh),$noise_color);
}
for($i=0;$i imageline($auimg,mt_rand(0,$imagesw),mt_rand(0,$imagesh),mt_rand(0,$imagesw),mt_rand(0,$imagesh),$line_color);
}
$mtrnd=rand(0,strlen($str)-4);
if($mtrnd%2)$mtrnd+=1;
$str = substr($str,$mtrnd,8);
$str = iconv(gb2312,utf-8,$str);
imagettftext($auimg, 20, 0, 16, 30, $font_color, $font, $str);
imagepng($auimg);
imagedestroy($auimg);
/*
 共同点就是验证码都借助于其它容器来保存如session,cookie等,否则就没有验证的意义了
 本文章由www.bkjia.com整,转载请注明来源谢谢合作。
http://www.bkjia.com/phpjc/444954.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/444954.htmltecharticlephp教程 中文与英文验证码程序代码 //英文验证码相对简单,不要作hex处理,直接用色彩值就ok了。如果 session_start(); function rand_create() { //通...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录