TP登录逻辑

<?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(){
         
    }   
}
<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>

  

 

posted @ 2018-03-16 11:57  小孩坏坏  阅读(215)  评论(0编辑  收藏  举报