PDO::ERRMODE_EXCEPTION]; try { $pdo = new PDO($dsn, $user, $pass, $options); } catch (PDOException $e) { die("Database connection failed: " . $e->getMessage()); } // ---------------- Helper Functions ---------------- function getUserById($pdo, $id) { $stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$id]); return $stmt->fetch(PDO::FETCH_ASSOC); } function addTransaction($pdo, $user_id, $type, $amount, $description) { $stmt = $pdo->prepare("INSERT INTO transactions (user_id, type, amount, description) VALUES (?, ?, ?, ?)"); $stmt->execute([$user_id, $type, $amount, $description]); } // ---------------- Authentication ---------------- if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['register'])) { $username = $_POST['username']; $email = $_POST['email']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $usdt_address = $_POST['usdt_address']; $ref_code = bin2hex(random_bytes(5)); $referred_by = null; if (!empty($_POST['referral_code'])) { $stmt = $pdo->prepare("SELECT id FROM users WHERE referral_code = ?"); $stmt->execute([$_POST['referral_code']]); $refUser = $stmt->fetch(PDO::FETCH_ASSOC); if ($refUser) $referred_by = $refUser['id']; } $stmt = $pdo->prepare("INSERT INTO users (username, email, password, faucetpay_usdt_address, referral_code, referred_by_id) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$username, $email, $password, $usdt_address, $ref_code, $referred_by]); echo ""; } if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?"); $stmt->execute([$email]); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['user_role'] = $user['role']; } else { echo ""; } } if (isset($_POST['claim_faucet'])) { $user = getUserById($pdo, $_SESSION['user_id']); $lastClaim = strtotime($user['last_faucet_claim']); $now = time(); if ($now - $lastClaim >= 86400) { $reward = 0.001; $stmt = $pdo->prepare("UPDATE users SET balance = balance + ?, last_faucet_claim = NOW() WHERE id = ?"); $stmt->execute([$reward, $user['id']]); addTransaction($pdo, $user['id'], 'faucet_claim', $reward, 'Daily faucet claim'); if ($user['referred_by_id']) { $ref_bonus = $reward * 0.1; $stmt = $pdo->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); $stmt->execute([$ref_bonus, $user['referred_by_id']]); addTransaction($pdo, $user['referred_by_id'], 'referral_commission', $ref_bonus, 'Referral commission'); } echo ""; } else { echo ""; } } } // ---------------- HTML Head ---------------- echo 'Muzalif Faucet Hub
'; // ---------------- Conditional Rendering ---------------- if (isset($_SESSION['user_id'])) { $user = getUserById($pdo, $_SESSION['user_id']); echo "

Welcome, {$user['username']}

"; echo "

Balance: {$user['balance']} USDT

"; echo "

Your Referral Link: ?ref={$user['referral_code']}

"; echo '
'; echo '
'; } else { echo '

Register

Login

'; } // ---------------- JavaScript ---------------- echo '
'; // ---------------- Logout Logic ---------------- if (isset($_POST['logout'])) { session_destroy(); header("Location: index.php"); exit; } ?>

Comments

Popular posts from this blog