Home >PHP Framework >ThinkPHP >How to hide the background in thinkphp
With the development of the Internet, website development has become a common need. In order to meet the different needs of developers, many development frameworks have emerged. In the field of PHP, we must have heard of the ThinkPHP framework. It is currently one of the most popular PHP development frameworks in China and an excellent open source framework.
ThinkPHP has a good documentation system, multiple programming specifications and powerful expansion capabilities. Among them, many features developed by TP5 provide convenience and security. Hiding the background is one of them.
So, how to hide the ThinkPHP backend? We need to do the following steps.
The first step is to set up a hidden folder (the folder name can be customized) and concentrate the background programs in this folder.
The second step is to find the route.php file in the config directory and enable the routing function.
The third step is to set routing rules and add routing rules in the route.php file.
Let’s analyze the above three steps in detail.
Step one: Set up a hidden folder
In ThinkPHP we need to create a new folder and store all background controller and template files in it. You can name the folder admin or something else, as appropriate. Create a new admin folder in the Web root directory, and create a new index.php file in this folder. After completing this step, you only need to access the file through the URL to enter the background. However, it should be noted that this approach is not safe. Others can still access the file through the URL, causing the backend to be invaded. So we need to take the next step.
Step 2: Turn on the routing function
The ThinkPHP framework has built-in routing function. The routing function allows us to specify what we need in a relative (or absolute) way when accessing. Access controllers and methods. This facilitates our development work. Search for "routing" or "route" in the route.php file, and you can easily find the configuration items that enable routing.
Change false in the code to true to enable the routing function.
Step 3: Set routing rules
After turning on the routing function, we add a routing rule in the route.php file to specify the access link of the default controller. An example is as follows:
Route::rule('/admin', 'admin/Index/index');
What this code means is: when you access localhost/admin, you actually access the index method of the Index controller under the admin module.
Through the above three steps, we can successfully hide the ThinkPHP backend. This greatly enhances the security of the background. In actual development, it is recommended to use the functions provided by the framework as much as possible to avoid code security problems caused by writing your own code.
Summary
ThinkPHP is an excellent open source framework with powerful expansion capabilities. Hiding the background is one of the very important security features that developers should master.
The above three steps can help you get started quickly and do a good job of hiding the background function.
Finally, it should be noted that the security of the framework is jointly responsible by the framework provider and the developer. The security of the system cannot depend on the responsibility of one person or party.
The above is the detailed content of How to hide the background in thinkphp. For more information, please follow other related articles on the PHP Chinese website!