欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php完整验证码代码 php 生成验证码 php 短信验证码 php验证码代

程序员文章站 2022-04-06 18:31:13
...
php 
require_once 'string.func.php';
//通过GD库做验证码/**
 *添加验证文字
 * @param int $type
 * @param int $length
*/function buildRandomString($type=1,$length=4){
    $row='';
    if($type==1){
        $row=join('',range(0, 9));
    }elseif($type==2){
        $row=join('', array_merge(range('a','z'),range('A', 'Z')));
    }elseif($type==3){
        $row=join('', array_merge(range('a','z'),range('A', 'Z'),range(0, 9)));
    };
    $row=str_shuffle($row);
   
    $row=substr($row,0,$length);
    return$row;
}
/**
 * 生成缩略图
 * @param int $type //包含数字或者英文
 * @param int $length 多少个字符
 * @param int $pixel 干扰小点的密度
 * @param int $dst_h 干扰线的密度
 * @param string //验证码在$_SESSION中的名字
 */function verifyImage($type=1,$length=4,$pixel=0,$line=0,$sess_name = "verify"){
    //session_start();
    //创建画布$width = 100;
    $height = 40;
    $image = imagecreatetruecolor ( $width, $height );
    $white = imagecolorallocate ( $image, 255, 255, 255 );
    $black = imagecolorallocate ( $image, 0, 0, 0 );
    //用填充矩形填充画布    imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
    $chars = buildRandomString ( $type, $length );
    $_SESSION [$sess_name] = $chars;
    //$fontfiles = array ("MSYH.TTF", "MSYHBD.TTF", "SIMLI.TTF", "SIMSUN.TTC", "SIMYOU.TTF", "STZHONGS.TTF" );$fontfiles = array ("SIMKAI.TTF" );
    //由于字体文件比较大,就只保留一个字体,如果有需要的同学可以自己添加字体,字体在你的电脑中的fonts文件夹里有,直接运行输入fonts就能看到相应字体for($i = 0; $i $length
相关标签: php 验证码