Home > PHP Framework > ThinkPHP > body text

How to hide admin.php in tp5

藏色散人
Release: 2021-11-10 17:11:16
Original
2804 people have browsed it

tp5隐藏admin.php的方法:1、定义入口文件admx.php,并在入口文件绑定admin模块;2、在config/app.php文件中,配置禁止访问admin;3、配置nginx伪静态即可。

How to hide admin.php in tp5

本文操作环境:windows7系统、thinkphp v5.1版、DELL G3电脑

tp5怎么隐藏admin.php?

tp5 隐藏后台

为了后台的安全,一般后端开发人员都会对后台路径进行隐藏。

踩了多天的坑,终于想到了,tp5.1隐藏后台目录的方法了。

假设我的后台目录为 "/admin"

1.定义入口文件admx.php(也可以是很难猜的文件名),并在入口文件绑定admin模块

<?php
 
// [ 应用入口文件 ]
namespace think;
 
 
define(&#39;CONFIG_PATH&#39;,__DIR__.&#39;/../config/&#39;);
// 加载基础文件
require __DIR__ . &#39;/../thinkphp/base.php&#39;;
 
 
 
 
// 执行应用并响应
Container::get(&#39;app&#39;)->bind(&#39;admin&#39;)->run()->send();
Copy after login

2.然后在config/app.php文件中,配置禁止访问admin

// 禁止访问模块
&#39;deny_module_list&#39;       => [&#39;common&#39;,&#39;admin&#39;],
Copy after login

测试: 通过域名+/admin 的方式已经无法访问,只能通过域名+admx.php的方式去访问,仔细观察URL你会发现,实际上admx.php == /admin。

目前这种方式是对代码改动最小的。

How to hide admin.php in tp5

3,nginx 伪静态的配置

location / {
if (!-e $request_filename){
rewrite  ^(.*)$  /index.php?s=$1  last;   break;
}
}
location /admx.php/ {
    if (!-e $request_filename) {
         rewrite  ^/admx.php/(.*)$  /admx.php?s=$1  last;
         break;
    }
}
Copy after login

 推荐学习:《PHP视频教程

The above is the detailed content of How to hide admin.php in tp5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
tp5
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!