简单的界面

ThinkPHP 3.2.3 验证码 生成和校验DEMO_html

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>

    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>


    <script>

        $(function () {
            //点击图片更换验证码
            $("#code").click(function()
            {
                $("#code").attr("src","__APP__/Home/Demo/verify?timestamp="+new Date().getTime());

            });
        });


</script>
</head>
<body>

<form action="__APP__/Home/Demo/check" method="post">
    <img id="code" src="__APP__/Home/Demo/verify">
    <input type="text" name="code"/>
    <input type="submit" value="提交">

</form>


</body>
</html>

处理程序:

 

 

<?php
/**
 * Created by PhpStorm.
 * User: 明明如月
 * Date: 2016/4/12
 * Time: 14:56
 */

namespace Home\Controller;
use Think\Controller;

class DemoController extends Controller
{

    function  index()
    {
        $this->display();
    }
   function verify()
   {
       $Verify =     new \Think\Verify();
       $Verify->fontSize = 30;
       $Verify->length   = 3;
       $Verify->useNoise = false;
       $Verify->entry();

   }


    function check()
    {

        $code = $_POST['code'];

        if(check_verify($code) === true)
        {
            $this->success("正确") ;
        }else
        {
            $this->error("验证码错误") ;
        }

    }

}

ThinkPHP 3.2.3 验证码 生成和校验DEMO_处理程序_02

 

ThinkPHP 3.2.3 验证码 生成和校验DEMO_jquery_03