• 注册表单无刷新验证+php无刷新刷新验证码


    原生Php无刷新(验证+刷新验证码)

    概述:本案例既实现了php注册页面的验证码无刷新刷新功能

    又实现了表单的无刷新验证,。效果绝对实用。本例只做为测试样例,未接数据库验证。

    源文件分2部分:code.phpzhuce.php

    其中code.php文件为验证码文件,zhuce.php文件为注册页面。

    闲话少说,代码献上。

    Code.php

    <?php
    session_start();
        //生成验证码图片
        Header("Content-type: image/PNG");
        $im = imagecreate(44,18); // 画一张指定宽高的图片
        $back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色
        imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中
        $vcodes = "";
        srand((double)microtime()*1000000);
        //生成4位数字
        for($i=0;$i<4;$i++){
        $font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色
        $authnum=rand(1,9);
        $vcodes.=$authnum;
        imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
        }
        $_SESSION['VCODE'] = $vcodes;
    
        for($i=0;$i<100;$i++) //加入干扰象素
        {
        $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
        imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数
        }
        ImagePNG($im);
        ImageDestroy($im);
    ?>
    <img src="code.php" />
    <?php 
     
    echo   $_SESSION['VCODE'];
    echo "211";
    ?>

    Zhuce.php

    <?php
    
    session_start();
    
    if(isset($_POST['auth'])){
    $auth = $_POST['auth'];
    //$test=$_POST['test'];  
    $error="验证码输入有误";
    $true="ok";
    if($_SESSION["VCODE"] == $auth)
    {
      echo $true; 
     header("location: http://www.xinhuanet.com/");
    }else
    {   
       $tests=$_POST['test'];
       echo $error;
    }
    }
    
    ?>
     
    <html>
    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head>
    <title>login</title>
    <style type="text/css">
    <!--
    #textboxs {
    height: 18px;
    width: 100px;
    }
    table{ margin:0 auto;}
    img{ width:60px; height:30px;}
    .text {
    font-size: 14px;
    vertical-align: bottom;
    color: #0000FF;
    }
    .style1 {
    font-size: 18px;
    color: #0000FF;
    font-family: "幼圆";
    }
    -->
    </style>
    <script language="JavaScript">
       function reloadcode()
       {
           var verify=document.getElementById('safecode');
           verify.setAttribute('src','code.php?'+Math.random());
           //这里必须加入随机数不然地址相同会重新加载
    }
     
     
    </script>
    </head>
    <body>
    <table width="200">
    <tr><td align="center" valign="bottom" class="style1" bgcolor="#C7D3F9">请输入验证码</td>
    </tr>
    </table>
    <form method="post" >
    <table width="200" border="0" bgcolor="C7D3F9">
      <tr>
        <td class="text">验证码:</td>
        <td align="right" valign="bottom"><input type="text" name="auth" id="textboxs"/></td>
      </tr>
    <tr><td><img src="code.php?act=yes" align="middle" id="safecode"></td></tr>
    </table>
    <table width="200"><tr><td align="right"><input type="button" value="看不清楚验证码" onClick="reloadcode();">
    <input name="submit" type="submit" value="Submit"></td></tr>
    <tr><td><input type="text" name="test" value="<?php if(isset($tests)){ echo $tests;}?>"></td></tr></table>
    </form>
    </body>
    </html>

    有关表单提交前的交互,这里不做详解,有兴趣的可以加我好友私聊!

  • 相关阅读:
    使用 BenchmarkDotnet 测试代码性能
    【UWP】对 Thickness 类型属性进行动画
    【Win10】单元测试中捕获异步方法的指定异常
    【Win10】让 TextBlock 按字符换行
    全国天气预报信息数据 API 功能简介与代码调用实战视频
    5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用
    获取任意链接文章正文 API 功能简介
    开放数据接口 API 简介与使用场景、调用方法
    程序员如何开始做一个自己的 Side Project?
    VSCode 必装的 10 个高效开发插件
  • 原文地址:https://www.cnblogs.com/xiaogou/p/5283070.html
Copyright © 2020-2023  润新知