Home >Backend Development >PHP Tutorial >PHPCMS simple method to modify background path
I have found many ways to modify the phpcms background path on the Internet, but they are all too cumbersome (personal feeling). I finally found a relatively simple modification method. I will share it with you here, hoping to learn from each other.
Step 1:
Create a folder in the root directory of the website. You will use this folder to enter the background login interface in the future, so the folder name must be a name that is not easy for others to guess. As a demonstration here, I will call it adminweb. Next, create a new file index.php in this folder with the content:
<?php <span>define</span>('PHPCMS_PATH', <span>realpath</span>(<span>dirname</span>(<span>__FILE__</span>) . '/..') . '/'<span>); </span><span>include</span> PHPCMS_PATH . '/phpcms/base.php'; <span>//</span><span> pc_base::creat_app();</span><span>$session_storage</span> = 'session_' . pc_base :: load_config('system', 'session_storage'<span>); pc_base </span>:: load_sys_class(<span>$session_storage</span><span>); </span><span>session_start</span><span>(); </span><span>$_SESSION</span>['right_enter'] = 1<span>; </span><span>unset</span>(<span>$session_storage</span><span>); </span><span>header</span>('location:../index.php?m=admin');
Step 2:
Create a new file in the phpcms/modules/admin/ folder MY_index.php, the content is:
<?php <span>defined</span>('IN_PHPCMS') or <span>exit</span>('No permission resources.'<span>); </span><span>class</span> MY_index <span>extends</span><span> index { </span><span>public</span><span>function</span><span> __construct() { </span><span>if</span> (<span>empty</span>(<span>$_SESSION</span>['right_enter'<span>])) { </span><span>header</span>('location:./'<span>); </span><span>exit</span><span>; } parent </span>::<span> __construct(); } </span><span>public</span><span>function</span><span> public_logout() { </span><span>$_SESSION</span>['right_enter'] = 0<span>; parent </span>::<span> public_logout(); } }</span>
This modification only requires two places. There are not so many steps, and the website background can only go through /adminweb, so It is not easy for others to find your backend entrance. What needs to be noted here is that if you log in with /adminweb, you press the original /admin.php
The above introduces the simple method of modifying the background path of PHPCMS, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.