// ========== V4 用户系统函数 ========== if (session_status() == PHP_SESSION_NONE) { session_start(); } function current_user_id() { return $_SESSION['user_id'] ?? 0; } function current_user($pdo) { $uid = current_user_id(); if (!$uid) return null; static $user = null; if ($user !== null) return $user; $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$uid]); $user = $stmt->fetch(); return $user; } function is_user_logged_in() { return !empty($_SESSION['user_id']); } function require_login() { if (!is_user_logged_in()) { header("Location: user_login.php?redirect=" . urlencode($_SERVER['REQUEST_URI'])); exit; } } function hash_password($password) { return password_hash($password, PASSWORD_DEFAULT); } function verify_password($password, $hash) { return password_verify($password, $hash); } // ========== V4 安全函数 ========== function is_ip_blacklisted($pdo, $ip) { $stmt = $pdo->prepare("SELECT id FROM ip_blacklist WHERE ip = ? AND (expires_at IS NULL OR expires_at > NOW())"); $stmt->execute([$ip]); return $stmt->fetch() ? true : false; } function check_login_attempts($pdo, $ip) { $stmt = $pdo->prepare("SELECT COUNT(*) FROM login_attempts WHERE ip = ? AND success = 0 AND created_at > DATE_SUB(NOW(), INTERVAL 15 MINUTE)"); $stmt->execute([$ip]); return $stmt->fetchColumn() >= 5; } function record_login_attempt($pdo, $username, $ip, $success) { $stmt = $pdo->prepare("INSERT INTO login_attempts (username, ip, success) VALUES (?, ?, ?)"); $stmt->execute([$username, $ip, $success ? 1 : 0]); } function get_banners($pdo) { $stmt = $pdo->query("SELECT * FROM banners WHERE status = 1 ORDER BY sort ASC, id ASC"); return $stmt->fetchAll(); }
Fatal error: Uncaught Error: Call to undefined function current_user_id() in /www/wwwroot/dy.1br.cn/download.php:36 Stack trace: #0 {main} thrown in /www/wwwroot/dy.1br.cn/download.php on line 36