天天看點

ThinkPHP 3.2.3 驗證碼 生成和校驗DEMO

簡單的界面

ThinkPHP 3.2.3 驗證碼 生成和校驗DEMO

<!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
ThinkPHP 3.2.3 驗證碼 生成和校驗DEMO