如图:

1.进入下面路径

2.创建一个password.php空文件
将下面代码放入其中,将 ‘your_password’ 替换为你想要的密码并保存。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 
 | <?php// 设置访问密码
 $password = 'your_password'; // 将 'your_password' 替换为你想要的密码
 
 // 检查是否已提交密码
 if (isset($_POST['password'])) {
 if ($_POST['password'] === $password) {
 // 密码正确,设置 Session 并跳转到首页
 session_start();
 $_SESSION['access_granted'] = true;
 header('Location: /'); // 将 '/' 替换为你的网站首页地址
 exit;
 } else {
 // 密码错误,显示错误信息
 $error = "密码错误,请重试。";
 }
 }
 ?>
 
 | 
将下面代码直接放入保存即可。
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 | <!DOCTYPE html><html>
 <head>
 <title>请输入访问密码</title>
 <style>
 body {
 display: flex;
 justify-content: center;
 align-items: center;
 height: 100vh;
 margin: 0;
 }
 
 form {
 text-align: center;
 }
 </style>
 </head>
 <body>
 <form method="post" action="">
 <h2>请输入访问密码</h2>
 <?php if (isset($error)) { echo "<p style='color: red;'>$error</p>"; } ?>
 <label for="password">密码:</label><br>
 <input type="password" id="password" name="password"><br><br>
 <button type="submit">提交</button>
 </form>
 </body>
 </html>
 
 | 
4.修改index.php文件
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | <?php// 引入密码验证脚本
 require_once 'password.php';
 
 // 检查是否已通过密码验证
 session_start();
 if (!isset($_SESSION['access_granted']) || $_SESSION['access_granted'] !== true) {
 // 未通过验证,显示密码输入表单
 require_once 'password_form.php';
 exit;
 }
 
 | 

5.修改你的后台,如:admin123.PHP
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 
 | <?php// 引入密码验证脚本
 require_once 'password.php';
 
 session_start();
 
 // 检查是否已通过密码验证
 if (!isset($_SESSION['access_granted']) || $_SESSION['access_granted'] !== true) {
 // 未通过验证,重定向到前台密码输入页面
 header('Location: /'); // 将 'password_form.php' 替换为你的密码输入页面的地址
 exit;
 }
 
 | 
