请问php网站后台密码怎么修改
// 假设用户已通过身份验证 $userId = $_SESSION['user_id']; // 获取表单数据 $newPassword = $_POST['new_password']; $confirmPassword = $_POST['confirm_password']; // 验证新密码 if ($newPassword !== $confirmPassword) { echo "新密码和确认密码不匹配!"; exit; } // 加载用户信息 $user = getUserById($userId); // 验证旧密码 if (!password_verify($_POST['old_password'], $user['password_hash'])) { echo "旧密码错误!"; exit; } // 更新密码 $newPasswordHash = password_hash($newPassword, PASSWORD_DEFAULT); updateUserPassword($userId, $newPasswordHash); // 清除会话 session_unset(); session_destroy(); echo "密码修改成功,请重新登录。";