$new_user, 'password' => md5($new_pass), 'role' => $new_role ]; file_put_contents($users_file, json_encode($users, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); header('Location: users.php'); exit; } } else { $error = '用户名和密码不能为空'; } } // 删除用户 if (isset($_GET['del']) && $_GET['del'] !== 'admin') { $users = array_filter($users, function($u) { return $u['username'] !== $_GET['del']; }); file_put_contents($users_file, json_encode(array_values($users), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); header('Location: users.php'); exit; } // 修改密码 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_pass'])) { $target = $_POST['target_user']; $new_pass = $_POST['new_password']; foreach ($users as &$u) { if ($u['username'] === $target && $target !== '') { $u['password'] = md5($new_pass); break; } } unset($u); file_put_contents($users_file, json_encode($users, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); $msg = '密码已修改'; header('Location: users.php'); exit; } // 修改角色 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['change_role'])) { $target = $_POST['target_user']; $new_role = $_POST['new_role'] === 'admin' ? 'admin' : 'user'; foreach ($users as &$u) { if ($u['username'] === $target && $target !== 'admin') { $u['role'] = $new_role; break; } } unset($u); file_put_contents($users_file, json_encode($users, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); header('Location: users.php'); exit; } ?> 用户管理

用户管理

用户名类型操作
管理员
删除 保护
返回管理首页