zoukankan      html  css  js  c++  java
  • 验证码

    gd库画图流程:

    1,创建画布

    2,创建各种颜料

    3,绘画

    4,保存成图片

    5,销毁

    html页面

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>验证</title>
    <script type="text/javascript">
    function update(th){
        th.src='001.php?_s='+Math.random();
    }
    </script>
    </head>
    <body>
        <form action='' method=''>
            验证码<input type='text' name='验证码'/><img src='001.php' onclick='update(this)'/><br/>
            <input type='submit' value='提交'/>
        </form>
    </body>
    </html>
    

     001.php生成验证码

    <?php
    // print_r(gd_info());//判断gd2库是否开启
    
    $rs=imagecreatetruecolor(50,30);//创建画布资源
    $gray=imagecolorallocate($rs, 100, 100, 100);
    
    $fontcolor=imagecolorallocate($rs, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255));
    
    $linecolor1=imagecolorallocate($rs, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));
    $linecolor2=imagecolorallocate($rs, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));
    $linecolor3=imagecolorallocate($rs, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));
    
    //填充颜色
    imagefill($rs, 0, 0, $gray);
    
    //随机字符串
    $str=substr(str_shuffle('ABCDEFGHJKMNOPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789'),0,4);
    
    //书写字符串
    imagestring($rs, 5, 8, 5, $str, $fontcolor);
    
    //画干扰线
    imageline($rs,0,mt_rand(0,30),50,mt_rand(0,30),$linecolor1);
    imageline($rs,0,mt_rand(0,30),50,mt_rand(0,30),$linecolor2);
    imageline($rs,0,mt_rand(0,30),50,mt_rand(0,30),$linecolor3);
    
    //输出
    header('content-type:image/png');
    imagepng($rs);
    //销毁
    imagedestroy($rs);
    ?>
    
  • 相关阅读:
    QAction使用
    QT学后感
    设置背景图片
    获取句柄的方法总结(尤其是对于dll而言)
    unixbench小试
    Java命令行之jar命令
    Java应用程序安装包制作工具简介
    Eclipse使用ant编译时的乱码问题
    Jboss4中使用配置发送邮件
    Exe4j注册码
  • 原文地址:https://www.cnblogs.com/lzzhuany/p/4783397.html
Copyright © 2011-2022 走看看