tp框架实现登录

Posted on 2018-03-15 15:16  神笔码农  阅读(317)  评论(0编辑  收藏  举报
<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
    public function login(){
        //显示页面
        if(empty($_POST)){
            $this->show();
        }else{
            //实现登录逻辑
            $uid = $_POST["uid"];
            $pwd = $_POST["pwd"];
             
            $db = D("Users");
            $arr = $db->find($uid);
            if($arr["pwd"]==$pwd&&!empty($pwd)){
                $url = U("mains");
                $this->success("登录成功!",$url);
            }else{
                $this->error("登陆失败!");//默认跳转到上一个界面
            }
        }
    }
    public function mains(){
         
    }   
}

<html>
<head>
</head>
<body>
 
<form action="" method="post">
    <div>用户名:<input type="text" name="uid" /></div>
    <div>密码:<input type="password" name="pwd"/></div>
    <input type="submit" value="登录"/>
</form>
 
</body>
</html>