thinkphp自定义后台admin登陆地址 隐藏后台登录地址
发布时间: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(自己设定的),如果不能与直接就跳转到首页,否则显示登录界面。
然后
现在你可以通过:http://你的域名/houtai 访问到后台了,其他路径都访问不到
$key = input('key');
if($key != 8686){
$this->redirect('http://www.baidu.com');
//$this->error ('你涉及非法登录');
}else{
return $this->fetch();
}