上面這段PHP後台登陸代碼實現免登陸

來源:互聯網
上載者:User
下面這段PHP後台登陸代碼實現免登陸
如果後台管理員帳號為admin,密碼為123456請問下面這段代碼如何?免登陸,麻煩知道的大哥直接給代碼謝謝了


PHP code
display(APP_PATH.'/Public/admin/login.html');    }        //產生驗證碼    public function vcode(){        import("ORG.Util.Image");        Image::buildImageVerify();//6,0,'png',1,20,'verify'    }        //登入檢測    public function check(){        if(empty($_POST['user_name'])){$this->error('帳號必須!');}        if(empty($_POST['user_pwd'])){$this->error('密碼必須!');}        if(function_exists('gd_info')){            if(empty($_POST['verify'])){$this->error('驗證碼必須!');}            if($_SESSION['verify']!=md5($_POST['verify'])){$this->error('驗證碼錯誤!');}        }        //產生認證條件        $map=array();        //支援使用綁定帳號登入        $map['admin_name']=$_POST['user_name'];        //$map["user_status"]=array('gt',0);//狀態        $rs=D("Admin.Admin");        $authInfo=$rs->where($map)->find();        //使用使用者名稱、密碼和狀態的方式進行認證        if(false === $authInfo) {            $this->error('帳號不存在或已禁用!');        }else {            if($authInfo['admin_pwd']!=md5($_POST['user_pwd'])){                $this->error('密碼錯誤!');            }            // 緩衝存取權限            $_SESSION[C('USER_AUTH_KEY')]=$authInfo['admin_id'];            $_SESSION['admin_ok']=$authInfo['admin_ok'];            $_SESSION['admin_name']=$authInfo['admin_name'];                        //$_SESSION['email']=$authInfo['admin_email'];            //$_SESSION['lastLoginTime']=$authInfo['admin_logintime'];            //$_SESSION['login_count']=$authInfo['admin_count'];            //if($authInfo['user_name']=='admin') {                //$_SESSION['administrator']        =    true;            //}                //儲存登入資訊            $ip=get_client_ip();            $data=array();            $data['admin_id']=$authInfo['admin_id'];            $data['admin_logintime']=time();            $data['admin_count']=array('exp','admin_count+1');            $data['admin_ip']=get_client_ip();            $rs->save($data);            redirect('index.php?s=Admin-Index');                            }    }            // 使用者登出    public function logout(){        if(isset($_SESSION[C('USER_AUTH_KEY')])) {            unset($_SESSION[C('USER_AUTH_KEY')]);            unset($_SESSION);            session_destroy();            $this->assign('jumpUrl','index.php?s=Admin-Login');            $this->success('登出成功!');        }else {            $this->error('已經登出!');        }    }        }?>


------解決方案--------------------
改寫 index 方法為
PHP code
    public function index(){        if ($_SESSION[C('USER_AUTH_KEY')]){            redirect("index.php?s=Admin-Index");        }        //$this->display(APP_PATH.'/Public/admin/login.html');            $_POST['user_name'] = 'admin';        $_POST['user_pwd'] = '123456';        $_POST['verify'] = 1;        $_SESSION['verify'] = md5($_POST['verify']);        $this->check();   }
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.