thinkphp自定義后臺admin登陸地址 隱藏后臺登錄地址
發(fā)布時間:2020-08-01
thinkphp5 自定義后臺admin登陸地址(配置路由,更改登陸login方法)
1、配置路由:tp5.0路由在"項目名/app/route.php"
<?php
use think\Route;Route::rule('houtai','admin/login/login?key=8686');
//設置只能通過houtai 這個路徑訪問到登陸界面,houtai 和key 你可以自定義
2、修改你原來后臺登陸方法"admin/login/login"方法 (比如原來你是用這個地址登陸后臺)
<?php
namespace app\admin\controller;use app\common\model\Admin;use houdunwang\crypt\Crypt;use think\Controller;class Login extends Controller{
public function login(){
if(request()->isPost()){
$res = (new Admin())->login(input('post.'));
if($res['valid'])
{
//$this->success($res['msg'],'admin/index/index');exit;
exit(json_encode(array('code'=>0,'msg'=>$res['msg'])));
}else{
//$this->error($res['msg']);exit;
exit(json_encode(array('code'=>1,'msg'=>$res['msg'])));
}
}
//判斷登錄地址傳過來的key等于8686不,如果不能與直接就跳轉到首頁,否則顯示登錄界面
$key = input('key');
if($key != 8686){
$this->redirect('http://www.baidu.com');
//$this->error ('你涉及非法登錄');
}else{
return $this->fetch();
}
}}
主要代碼在于下面這段
原理:
因為你后臺的所有控制器都繼承了common這個文件,在這個文件里面判斷都是否登錄,沒有登錄都需要跳轉到admin/login/login這個登錄界面。
所以
你只要在這個登錄控制器判斷從路由傳過來的key等不等于8686(自己設定的),如果不能與直接就跳轉到首頁,否則顯示登錄界面。
然后
現(xiàn)在你可以通過:http://你的域名/houtai 訪問到后臺了,其他路徑都訪問不到
$key = input('key');
if($key != 8686){
$this->redirect('http://www.baidu.com');
//$this->error ('你涉及非法登錄');
}else{
return $this->fetch();
}