php------验证码

改代码只是简单实现了验证码,需要后续进行修改完善
PHP代码:TP_3.2.2/Home/Control/LoginController.class.php
?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 2018/4/16
 * Time: 13:13
 */

namespace Home\Controller;


use Think\Controller;

function check_verify($code, $id = ""){
    $verify = new \Think\Verify();
    return $verify->check($code, $id);
}

class loginController extends Controller
{
    /**
     *
     * 验证码生成
     */
    public function verify_c(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = '1';
        $Verify->imageW = 130;
        $Verify->imageH = 50;
        //$Verify->expire = 600;
        $Verify->entry();
    }

    function login(){
        $this->display('log/login');
    }
    function jumppage(){
        echo "jum.......";
        $this->display('index/index');
    }
    /**
     *
     */
    function getinfo()
    {
     //   echo I('get.age'); // 相当于 $_GET['id']

        if(0==strcasecmp("1",I('post.fname')))
        {
            echo "姓名验证通过";
        }else
        {
            echo "姓名验证没有通过";
        }
        if(0==strcasecmp("1",I('post.age')))
        {
            echo "ps验证通过";
        }else
        {
            echo "ps验证没有通过";
        }
        $verify = I('post.verify','');
        if(!check_verify($verify)){
            $this->error("亲,验证码输错了哦!",$this->site_url,9);
        }else{

            echo I('post.verify');
        }

          //  header('jump','login/jumppage');
         $this->success("正在登录",U('base/login'));//此处是跳转到另一个页面
    }

}

网页端代码: TP_3.2.2/Home/View/log/login.html
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> 登录界面 </title>
</head>
<body>
<form action="{:U('login/getinfo')}" method="post">
    <br>
    id: <input type="text" name="fname">
    <br>
<!--    ps: <input type="reset" name="age">  此处为了尝试重置恩建-->
    <p>

        <input name="verify" width="50%" height="50" class="captcha-text" placeholder="验证码" type="text">
        <img width="10%" class="left15" height="30" alt="验证码" src="{:U('login/verify_c')}" title="点击刷新">
        <br>
        <br>
    </p>
     <input type="submit" >
</form>
</body>
</html>

浏览器端输入:http://127.0.0.1:90/TP_3.2.2/index.php/Home/login/login


猜你喜欢

转载自blog.csdn.net/qq_39584315/article/details/79976089