CCSWebsite/console/admin/admin_delete_user.php
2025-06-17 01:43:15 +00:00

49 lines
1.1 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
require_once('./config.php');
// 验证用户是否登录
if (!isset($_SESSION['user_id'])) {
die("未授权访问!");
}
// 获取当前用户ID
$currentUserId = $_SESSION['user_id'];
// 查询当前用户等级
$stmt = $conn->prepare("SELECT level FROM users WHERE id = ?");
$stmt->bind_param("i", $currentUserId);
$stmt->execute();
$result = $stmt->get_result();
$userData = $result->fetch_assoc();
$stmt->close();
// 检查是否为管理员等级4
if ($userData['level'] != 4) {
die("权限不足!");
}
// 处理删除用户逻辑
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$userId = $_POST['user_id'];
// 先删除关联的玩家数据
$stmt = $conn->prepare("DELETE FROM players WHERE user_id = ?");
$stmt->bind_param("i", $userId);
$stmt->execute();
$stmt->close();
// 再删除用户
$stmt = $conn->prepare("DELETE FROM users WHERE id = ?");
$stmt->bind_param("i", $userId);
if ($stmt->execute()) {
echo "用户删除成功!";
} else {
echo "删除失败:" . $stmt->error;
}
$stmt->close();
}
$conn->close();
?>