登录  /  注册
类封装验证图怎么输出+JS
php中文网
发布: 2016-06-13 13:43:33
原创
605人浏览过

类封装验证图如何输出+JS
这是用类封装的一个验证图 我的问题是如何在另外一个页面上调用它
PHP code

randcodelength = 5;
        $this->imgWidth = 80;
        $this->imgHeight = 20;
        $this->codelength = count($this->code)-1;                //获取数组长度当随机范围

        $this->createrandcode();
        $this->createimg();
        $this->createString();
        $this->drawline($this->line);
        $this->ending();

    }
    function createrandcode(){
        for($i=0;$i<$this->randcodelength;$i++){                //初始化验证码
            $this->randcode .= $this->code[rand(0,$this->codelength)];
        }
    }
    function createimg(){                                        //创建图片 前景 背景颜色
        $this->image = imagecreatetruecolor($this->imgWidth,$this->imgHeight);
        $this->background = imagecolorallocate($this->image,0,0,0);
        $this->foreground = imagecolorallocate($this->image,255,255,255);
    }
    function createString(){                                    //创建字符串
        imagestring($this->image,5,rand(5,35),0,$this->randcode,$this->foreground);
    }
    function drawline($some){
        for($i=0;$i<$some;$i++){
            imageline($this->image,rand(1,$this->imgWidth),rand(1,$this->imgHeight),rand(1,$this->imgWidth),rand(1,$this->imgHeight),$this->foreground);
        }
    }
    function ending(){
        ob_clean();                                    //抛弃缓存内容
        header("Content-type: image/jpeg");
        imagejpeg($this->image);
    }
}
?>


登录后复制

下面是输出页面
PHP code



登录后复制





无标题文档
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学