Compare commits
No commits in common. "main" and "Backup" have entirely different histories.
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"python-envs.defaultEnvManager": "ms-python.python:system",
|
|
||||||
"python-envs.pythonProjects": []
|
|
||||||
}
|
|
||||||
251
gamefix.php
251
gamefix.php
@ -1,251 +0,0 @@
|
|||||||
<?php
|
|
||||||
session_start();
|
|
||||||
include "koneksi.php";
|
|
||||||
|
|
||||||
// =============================
|
|
||||||
// REQUIRE LOGIN
|
|
||||||
// =============================
|
|
||||||
if (!isset($_SESSION['user_id'])) {
|
|
||||||
header("Location: loginn.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================
|
|
||||||
// AJAX HANDLER
|
|
||||||
// =============================
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
|
||||||
$user_id = intval($_SESSION['user_id']);
|
|
||||||
$action = $_POST['action'];
|
|
||||||
|
|
||||||
// ========= TOP UP ==========
|
|
||||||
if ($action === 'topup') {
|
|
||||||
$amount = intval($_POST['amount']);
|
|
||||||
$bank_method = trim($_POST['bank_method']);
|
|
||||||
|
|
||||||
if ($amount <= 0) {
|
|
||||||
echo json_encode(['status'=>'error','message'=>'Jumlah top up tidak valid.']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UPDATE SALDO (BANK)
|
|
||||||
$sql = "UPDATE users SET bank = bank + ? WHERE id = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "ii", $amount, $user_id);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
|
|
||||||
// Ambil saldo baru
|
|
||||||
$sql2 = "SELECT bank FROM users WHERE id = ?";
|
|
||||||
$stmt2 = mysqli_prepare($conn, $sql2);
|
|
||||||
mysqli_stmt_bind_param($stmt2, "i", $user_id);
|
|
||||||
mysqli_stmt_execute($stmt2);
|
|
||||||
$result = mysqli_stmt_get_result($stmt2);
|
|
||||||
$row = mysqli_fetch_assoc($result);
|
|
||||||
mysqli_stmt_close($stmt2);
|
|
||||||
|
|
||||||
$_SESSION['bank'] = intval($row['bank']);
|
|
||||||
|
|
||||||
echo json_encode([
|
|
||||||
'status' => 'ok',
|
|
||||||
'bank' => $_SESSION['bank'],
|
|
||||||
'message' => 'Top up berhasil.'
|
|
||||||
]);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========= SET BANK (saldo game win/lose) ===========
|
|
||||||
if ($action === 'set_balance') {
|
|
||||||
$newBank = intval($_POST['balance']);
|
|
||||||
if ($newBank < 0) {
|
|
||||||
echo json_encode(['status'=>'error','message'=>'Bank tidak valid']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE users SET bank = ? WHERE id = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "ii", $newBank, $user_id);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
|
|
||||||
$_SESSION['bank'] = $newBank;
|
|
||||||
|
|
||||||
echo json_encode(['status'=>'ok','bank'=>$newBank]);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode(['status'=>'error','message'=>'Action tidak dikenal']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =============================
|
|
||||||
// LOAD USER DATA NORMAL
|
|
||||||
// =============================
|
|
||||||
$user_id = intval($_SESSION['user_id']);
|
|
||||||
|
|
||||||
$sql = "SELECT username, bank FROM users WHERE id = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "i", $user_id);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$res = mysqli_stmt_get_result($stmt);
|
|
||||||
$user = mysqli_fetch_assoc($res);
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
|
|
||||||
if (!$user) {
|
|
||||||
session_destroy();
|
|
||||||
header("Location: loginn.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SESSION['username'] = $user['username'];
|
|
||||||
$_SESSION['bank'] = intval($user['bank']);
|
|
||||||
|
|
||||||
$username = htmlspecialchars($_SESSION['username']);
|
|
||||||
$bank = intval($_SESSION['bank']);
|
|
||||||
?>
|
|
||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Blackjack [21]</title>
|
|
||||||
<link rel="stylesheet" href="cliff.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="table">
|
|
||||||
<header>
|
|
||||||
<h1>Blackjack [21]</h1>
|
|
||||||
|
|
||||||
<div class="controls">
|
|
||||||
<div>
|
|
||||||
Signed in as: <strong><?php echo $username; ?></strong>
|
|
||||||
<button id="topup-btn">Top Up</button>
|
|
||||||
<a href="logout.php" class="btn-danger">Logout</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="margin-top:10px;">
|
|
||||||
<div class="chip">Bank: Rp <span id="bank-display"><?php echo number_format($bank,0,',','.'); ?></span></div>
|
|
||||||
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main>
|
|
||||||
<div id="game-area"></div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer>OCA GameHub - Blackjack [21]</footer>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ========== MODAL TOP UP ========== -->
|
|
||||||
<div id="topup-modal" class="modal" style="display:none;">
|
|
||||||
<div class="modal-content">
|
|
||||||
<span class="close" id="close-topup">×</span>
|
|
||||||
|
|
||||||
<h2>Top Up Saldo</h2>
|
|
||||||
|
|
||||||
<div id="topup-msg" style="display:none;"></div>
|
|
||||||
|
|
||||||
<p><strong>Pemain:</strong> <?php echo $username; ?></p>
|
|
||||||
<p><strong>Saldo sekarang:</strong> Rp <span id="modal-bank"><?php echo number_format($bank,0,',','.'); ?></span></p>
|
|
||||||
|
|
||||||
<form id="topup-form">
|
|
||||||
<label>Metode:</label>
|
|
||||||
<select id="bank-method">
|
|
||||||
<option value="">-- pilih --</option>
|
|
||||||
<option value="bca">BCA</option>
|
|
||||||
<option value="bni">BNI</option>
|
|
||||||
<option value="mandiri">Mandiri</option>
|
|
||||||
<option value="cimb">CIMB</option>
|
|
||||||
<option value="ewallet">E-Wallet</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label>Jumlah (Rp):</label>
|
|
||||||
<input type="number" id="topup-amount" min="1">
|
|
||||||
|
|
||||||
<button type="submit">Top Up</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let bank = <?php echo $bank; ?>;
|
|
||||||
|
|
||||||
// Format rupiah
|
|
||||||
function formatIDR(n) {
|
|
||||||
return Number(n).toLocaleString('id-ID');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update UI
|
|
||||||
function refreshBankUI() {
|
|
||||||
document.getElementById("bank-display").innerText = formatIDR(bank);
|
|
||||||
document.getElementById("modal-bank").innerText = formatIDR(bank);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modal
|
|
||||||
const modal = document.getElementById("topup-modal");
|
|
||||||
document.getElementById("topup-btn").onclick = () => modal.style.display = "flex";
|
|
||||||
document.getElementById("close-topup").onclick = () => modal.style.display = "none";
|
|
||||||
|
|
||||||
// ====== Top Up Submit ======
|
|
||||||
document.getElementById("topup-form").onsubmit = function(e){
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
let amount = parseInt(document.getElementById("topup-amount").value);
|
|
||||||
let method = document.getElementById("bank-method").value;
|
|
||||||
|
|
||||||
if (!method) { alert("Pilih metode dulu"); return; }
|
|
||||||
if (amount <= 0) { alert("Jumlah tidak valid"); return; }
|
|
||||||
|
|
||||||
let data = new URLSearchParams();
|
|
||||||
data.append("action","topup");
|
|
||||||
data.append("amount",amount);
|
|
||||||
data.append("bank_method",method);
|
|
||||||
|
|
||||||
fetch("game.php", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {"Content-Type":"application/x-www-form-urlencoded"},
|
|
||||||
body: data.toString()
|
|
||||||
})
|
|
||||||
.then(r=>r.json())
|
|
||||||
.then(res=>{
|
|
||||||
if(res.status === "ok"){
|
|
||||||
bank = res.bank;
|
|
||||||
refreshBankUI();
|
|
||||||
alert("Top up berhasil!");
|
|
||||||
modal.style.display = "none";
|
|
||||||
} else {
|
|
||||||
alert(res.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// ====== Called from JS game (win/lose) ======
|
|
||||||
window.persistBalanceToServer = function(newBank){
|
|
||||||
let data = new URLSearchParams();
|
|
||||||
data.append("action","set_balance");
|
|
||||||
data.append("balance",newBank);
|
|
||||||
|
|
||||||
return fetch("game.php", {
|
|
||||||
method:"POST",
|
|
||||||
headers:{"Content-Type":"application/x-www-form-urlencoded"},
|
|
||||||
body:data.toString()
|
|
||||||
})
|
|
||||||
.then(r=>r.json())
|
|
||||||
.then(res=>{
|
|
||||||
if(res.status === "ok"){
|
|
||||||
bank = res.bank;
|
|
||||||
refreshBankUI();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// untuk script game
|
|
||||||
window.getBank = () => bank;
|
|
||||||
window.setBank = (v) => { bank = v; refreshBankUI(); };
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="ody git.js"></script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
92
html.php
92
html.php
@ -1,58 +1,68 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
include "koneksi.php";
|
// If not logged in, redirect to login
|
||||||
|
if (!isset($_SESSION['username'])) {
|
||||||
if (!isset($_SESSION['user_id'])) {
|
header('Location: loginn.php');
|
||||||
header("Location: loginn.php");
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selalu ambil saldo dari DATABASE
|
|
||||||
$query = "SELECT bank FROM users WHERE id = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $query);
|
|
||||||
mysqli_stmt_bind_param($stmt, "i", $_SESSION['user_id']);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
$data = mysqli_fetch_assoc($result);
|
|
||||||
|
|
||||||
$currentBank = intval($data["bank"]);
|
|
||||||
$_SESSION["bank"] = $currentBank;
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="id">
|
<html lang="id">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" href="login.css">
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<title>Top Up</title>
|
<title>Blackjack [21] - OCA GameHub</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="cliff.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="table" role="application" aria-label="Blackjack tanpa iklan">
|
||||||
|
<header>
|
||||||
|
<h1> Blackjack [21] </h1>
|
||||||
|
<div class="controls">
|
||||||
|
<div style="display:flex;gap:12px;align-items:center;margin-bottom:8px;">
|
||||||
|
<div>Signed in as: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></div>
|
||||||
|
<a href="topup.php" style="text-decoration:none;padding:6px 10px;background:#3b82f6;color:#fff;border-radius:6px;">Top Up</a>
|
||||||
|
<a href="logout.php" style="text-decoration:none;padding:6px 10px;background:#ef4444;color:#fff;border-radius:6px;">Logout</a>
|
||||||
|
</div>
|
||||||
|
<div class="info">
|
||||||
|
<div class="chip">Bank: <span id="balance"><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></span></div>
|
||||||
|
<div class="chip">Taruhan: <span id="current-bet">0</span></div>
|
||||||
|
</div>
|
||||||
|
<div class="bet">
|
||||||
|
<input id="bet-input" type="number" min="1" value="50" />
|
||||||
|
<button id="bet-btn">Pasang Taruhan</button>
|
||||||
|
<button id="new-round" class="secondary"> Reset </button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
<h2>Top Up Saldo</h2>
|
<main>
|
||||||
|
<div class="board" id="dealer-area">
|
||||||
|
<div class="section-title">Dealer</div>
|
||||||
|
<div class="hand" id="dealer-hand"></div>
|
||||||
|
<div class="values" id="dealer-value"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>User: <b><?= $_SESSION['username'] ?></b></p>
|
<div class="board" id="player-area">
|
||||||
<p>Saldo Bank Sekarang: <b>Rp <?= number_format($currentBank, 0, ',', '.') ?></b></p>
|
<div class="section-title">Pemain</div>
|
||||||
|
<div class="hand" id="player-hand"></div>
|
||||||
|
<div class="values" id="player-value"></div>
|
||||||
|
|
||||||
<?php if ($message): ?>
|
<div class="actions" id="action-buttons">
|
||||||
<div style="color:<?= $message_type == 'success' ? 'lime' : 'red' ?>;">
|
<button id="hit">Hit</button>
|
||||||
<?= $message ?>
|
<button id="stand">Stand</button>
|
||||||
</div>
|
<button id="double">Double</button>
|
||||||
<?php endif; ?>
|
</div>
|
||||||
|
<div class="message" id="message"></div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
<form method="POST">
|
<footer>
|
||||||
<label>Pilih Bank :</label><br>
|
OCA GameHub - <code> Blackjack_[21] - </code> Semoga menang bosq
|
||||||
<input type="radio" name="bank_method" value="bca">BCA<br>
|
</footer>
|
||||||
<input type="radio" name="bank_method" value="bni">BNI<br>
|
</div>
|
||||||
<input type="radio" name="bank_method" value="mandiri">Mandiri<br><br>
|
|
||||||
|
|
||||||
<label>Jumlah Top Up:</label>
|
|
||||||
<input type="number" name="amount" required><br><br>
|
|
||||||
|
|
||||||
<button type="submit">Top Up</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<br>
|
|
||||||
<a href="html.php">Kembali</a>
|
|
||||||
|
|
||||||
|
<script src="ody git.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
141
loginn.php
141
loginn.php
@ -1,116 +1,67 @@
|
|||||||
<?php
|
<?php
|
||||||
include "koneksi.php";
|
include "koneksi.php";
|
||||||
session_start();
|
|
||||||
|
|
||||||
$error = '';
|
$error = '';
|
||||||
if(isset($_POST['login'])){
|
if(isset($_POST['login'])){
|
||||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
// PAKAI KOLOM BANK, BUKAN BALANCE
|
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
|
||||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
$result = mysqli_query($conn, $sql);
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
|
|
||||||
if (mysqli_num_rows($result) > 0) {
|
if (mysqli_num_rows($result) > 0) {
|
||||||
$user = mysqli_fetch_assoc($result);
|
$user = mysqli_fetch_assoc($result);
|
||||||
|
session_start();
|
||||||
if($password === $user['password']) {
|
$_SESSION['username'] = $user['username'];
|
||||||
|
// ensure balance key exists
|
||||||
// SESSION PAKAI BANK
|
$_SESSION['balance'] = isset($user['balance']) ? (int)$user['balance'] : 0;
|
||||||
$_SESSION['user_id'] = $user['id'];
|
header("Location: html.php");
|
||||||
$_SESSION['username'] = $user['username'];
|
exit;
|
||||||
$_SESSION['bank'] = intval($user['bank']);
|
|
||||||
|
|
||||||
$update_sql = "UPDATE users SET last_login = NOW() WHERE id = ?";
|
|
||||||
$update_stmt = mysqli_prepare($conn, $update_sql);
|
|
||||||
mysqli_stmt_bind_param($update_stmt, "i", $user['id']);
|
|
||||||
mysqli_stmt_execute($update_stmt);
|
|
||||||
|
|
||||||
header("Location: html.php");
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
$error = 'Invalid username or password.';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$error = 'Invalid username or password.';
|
$error = 'Invalid username or password.';
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<!-- ... form login tetap sama ... -->
|
|
||||||
|
|
||||||
<?php
|
<!DOCTYPE html>
|
||||||
include "koneksi.php";
|
<html lang="en">
|
||||||
session_start();
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Login</title>
|
||||||
|
<link rel="stylesheet" href="login.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="logo">
|
||||||
|
<h1>OCAGamingHub</h1>
|
||||||
|
<p>Welcome back — sign in to continue</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
$error = '';
|
<div class="form-container">
|
||||||
$success = '';
|
<div class="card-icon">♠</div>
|
||||||
|
|
||||||
if(isset($_POST['register'])){
|
<?php if(!empty($error)): ?>
|
||||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
<div class="error-message show"><?=htmlspecialchars($error)?></div>
|
||||||
$password = $_POST['password'];
|
<?php endif; ?>
|
||||||
$confirm_password = $_POST['confirm_password'];
|
|
||||||
|
|
||||||
if(empty($username) || empty($password)) {
|
<form action="loginn.php" method="POST">
|
||||||
$error = 'All fields are required.';
|
<div class="form-group">
|
||||||
} elseif($password !== $confirm_password) {
|
<label for="username">Username</label>
|
||||||
$error = 'Passwords do not match.';
|
<input id="username" name="username" type="text" placeholder="Enter username" required>
|
||||||
} elseif(strlen($password) < 6) {
|
</div>
|
||||||
$error = 'Password must be at least 6 characters.';
|
|
||||||
} else {
|
|
||||||
$check_sql = "SELECT id FROM users WHERE username = ?";
|
|
||||||
$check_stmt = mysqli_prepare($conn, $check_sql);
|
|
||||||
mysqli_stmt_bind_param($check_stmt, "s", $username);
|
|
||||||
mysqli_stmt_execute($check_stmt);
|
|
||||||
mysqli_stmt_store_result($check_stmt);
|
|
||||||
|
|
||||||
if(mysqli_stmt_num_rows($check_stmt) > 0) {
|
<div class="form-group">
|
||||||
$error = 'Username already exists.';
|
<label for="password">Password</label>
|
||||||
} else {
|
<input id="password" name="password" type="password" placeholder="Enter password" required>
|
||||||
$hashed_password = $password;
|
</div>
|
||||||
|
|
||||||
// INSERT KE KOLOM BANK, BUKAN BALANCE
|
<div class="button-group">
|
||||||
$insert_sql = "INSERT INTO users (username, password, bank, created_at)
|
<button type="submit" name="login" class="btn btn-signin">Sign In</button>
|
||||||
VALUES (?, ?, 1000, NOW())";
|
<a href="register.php" class="btn btn-signup">Sign Up</a>
|
||||||
$insert_stmt = mysqli_prepare($conn, $insert_sql);
|
</div>
|
||||||
mysqli_stmt_bind_param($insert_stmt, "ss", $username, $hashed_password);
|
|
||||||
|
|
||||||
if(mysqli_stmt_execute($insert_stmt)) {
|
</form>
|
||||||
$success = 'Registration successful! You can now login.';
|
</div>
|
||||||
|
</div>
|
||||||
$user_id = mysqli_insert_id($conn);
|
</body>
|
||||||
$_SESSION['user_id'] = $user_id;
|
</html>
|
||||||
$_SESSION['username'] = $username;
|
|
||||||
$_SESSION['bank'] = 1000;
|
|
||||||
|
|
||||||
header("Location: html.php");
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
$error = 'Registration failed. Please try again.';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<?
|
|
||||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
|
|
||||||
if ($row = mysqli_fetch_assoc($result)) {
|
|
||||||
|
|
||||||
if ($password === $row['password']) {
|
|
||||||
|
|
||||||
$_SESSION['user_id'] = $row['id'];
|
|
||||||
$_SESSION['username'] = $row['username'];
|
|
||||||
$_SESSION['bank'] = intval($row['bank']); // ← INI YANG PENTING
|
|
||||||
|
|
||||||
header("Location: html.php");
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
413
ody git.js
413
ody git.js
@ -1,23 +1,14 @@
|
|||||||
|
// SET MESSAGE (WIN/LOSE)
|
||||||
// =========================
|
function setMessage(text, status){
|
||||||
// SET MESSAGE
|
messageEl.textContent = text;
|
||||||
// =========================
|
messageEl.className = status; // 'win', 'lose', atau '' (tie)
|
||||||
function setMessage(text, status) {
|
|
||||||
if (messageEl) {
|
|
||||||
messageEl.textContent = text;
|
|
||||||
messageEl.className = status;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
// Simple Blackjack implementation
|
||||||
// KONSTANTA KARTU
|
const SUITS = ['♠','♥','♦','♣'];
|
||||||
// =========================
|
const RANKS = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
|
||||||
const SUITS = ['♠', '♥', '♦', '♣'];
|
|
||||||
const RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
|
|
||||||
|
|
||||||
// =========================
|
// DOM
|
||||||
// DOM ELEMENTS
|
|
||||||
// =========================
|
|
||||||
const dealerHandEl = document.getElementById('dealer-hand');
|
const dealerHandEl = document.getElementById('dealer-hand');
|
||||||
const playerHandEl = document.getElementById('player-hand');
|
const playerHandEl = document.getElementById('player-hand');
|
||||||
const dealerValueEl = document.getElementById('dealer-value');
|
const dealerValueEl = document.getElementById('dealer-value');
|
||||||
@ -32,148 +23,67 @@ const doubleBtn = document.getElementById('double');
|
|||||||
const newRoundBtn = document.getElementById('new-round');
|
const newRoundBtn = document.getElementById('new-round');
|
||||||
const messageEl = document.getElementById('message');
|
const messageEl = document.getElementById('message');
|
||||||
|
|
||||||
// TOPUP DOM
|
|
||||||
const topupBtn = document.getElementById('topup-btn');
|
|
||||||
const topupModal = document.getElementById('topup-modal');
|
|
||||||
const topupForm = document.getElementById('topup-form');
|
|
||||||
const topupMessage = document.getElementById('topup-message');
|
|
||||||
const modalAmount = document.getElementById('modal-amount');
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// VARIABEL GAME
|
|
||||||
// =========================
|
|
||||||
let deck = [];
|
let deck = [];
|
||||||
let dealer = [];
|
let dealer = [];
|
||||||
let player = [];
|
let player = [];
|
||||||
let dealerHidden = true;
|
let dealerHidden = true;
|
||||||
let balance = 0;
|
let balance = 1000;
|
||||||
let currentBet = 0;
|
let currentBet = 0;
|
||||||
let inRound = false;
|
let inRound = false;
|
||||||
|
|
||||||
// =========================================
|
function makeDeck(){
|
||||||
// AMBIL VALUE DARI PHP (HIDDEN INPUT)
|
|
||||||
// =========================================
|
|
||||||
let gameBalance = parseInt(document.getElementById('php-balance').value);
|
|
||||||
let userId = parseInt(document.getElementById('php-userid').value);
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// UPDATE BALANCE DISPLAY
|
|
||||||
// =========================
|
|
||||||
function updateBalanceDisplay() {
|
|
||||||
if (balanceEl) balanceEl.textContent = gameBalance.toLocaleString('id-ID');
|
|
||||||
const modalBalance = document.getElementById('modal-balance');
|
|
||||||
if (modalBalance) modalBalance.textContent = gameBalance.toLocaleString('id-ID');
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// SYNC KE SERVER
|
|
||||||
// =========================
|
|
||||||
async function syncBalanceToServer() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('update_balance.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ userId, balance: gameBalance })
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
return data.success;
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error:", err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// UPDATE SESSION PHP
|
|
||||||
// =========================
|
|
||||||
async function updateSessionBalance() {
|
|
||||||
try {
|
|
||||||
await fetch('update_session.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ balance: gameBalance })
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error:", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// UPDATE BALANCE LOGIC
|
|
||||||
// =========================
|
|
||||||
function updateGameBalance(amount, type) {
|
|
||||||
if (type === 'win') gameBalance += amount;
|
|
||||||
else if (type === 'loss') gameBalance -= amount;
|
|
||||||
else if (type === 'bet') gameBalance -= amount;
|
|
||||||
else if (type === 'refund') gameBalance += amount;
|
|
||||||
|
|
||||||
updateBalanceDisplay();
|
|
||||||
syncBalanceToServer();
|
|
||||||
updateSessionBalance();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.updateGameBalance = updateGameBalance;
|
|
||||||
window.gameBalance = gameBalance;
|
|
||||||
window.userId = userId;
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// FUNGSI KARTU
|
|
||||||
// =========================
|
|
||||||
function makeDeck() {
|
|
||||||
deck = [];
|
deck = [];
|
||||||
for (const s of SUITS) {
|
for(const s of SUITS){
|
||||||
for (const r of RANKS) deck.push({ suit: s, rank: r });
|
for(const r of RANKS){
|
||||||
|
deck.push({suit:s,rank:r});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shuffle() {
|
function shuffle(){
|
||||||
for (let i = deck.length - 1; i > 0; i--) {
|
for(let i=deck.length-1;i>0;i--){
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
const j = Math.floor(Math.random()*(i+1));
|
||||||
[deck[i], deck[j]] = [deck[j], deck[i]];
|
[deck[i],deck[j]] = [deck[j],deck[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cardValue(card) {
|
function cardValue(card){
|
||||||
if (card.rank === 'A') return [1, 11];
|
const r = card.rank;
|
||||||
if (['J', 'Q', 'K'].includes(card.rank)) return [10];
|
if(r==='A') return [1,11];
|
||||||
return [parseInt(card.rank)];
|
if(['J','Q','K'].includes(r)) return [10];
|
||||||
|
return [parseInt(r,10)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function handValues(hand) {
|
function handValues(hand){
|
||||||
let totals = [0];
|
let totals = [0];
|
||||||
|
for(const c of hand){
|
||||||
for (const card of hand) {
|
const vals = cardValue(c);
|
||||||
const cv = cardValue(card);
|
|
||||||
const newTotals = [];
|
const newTotals = [];
|
||||||
|
for(const t of totals){
|
||||||
totals.forEach(t => cv.forEach(v => newTotals.push(t + v)));
|
for(const v of vals){ newTotals.push(t+v); }
|
||||||
|
}
|
||||||
totals = [...new Set(newTotals)];
|
totals = Array.from(new Set(newTotals));
|
||||||
}
|
}
|
||||||
|
const valid = totals.filter(t=>t<=21);
|
||||||
const valid = totals.filter(t => t <= 21);
|
if(valid.length) return Math.max(...valid);
|
||||||
return valid.length ? Math.max(...valid) : Math.min(...totals);
|
return Math.min(...totals);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderHand(el, hand, hideFirst = false) {
|
function renderHand(el,hand,hideFirst=false){
|
||||||
el.innerHTML = '';
|
el.innerHTML='';
|
||||||
|
hand.forEach((c,i)=>{
|
||||||
hand.forEach((c, i) => {
|
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
|
div.className='card'+(c.suit==='♥'||c.suit==='♦'?' red':'');
|
||||||
|
|
||||||
if (hideFirst && i === 0) {
|
if(hideFirst && i===0){
|
||||||
div.className = 'card back';
|
div.className='card back';
|
||||||
div.textContent = 'HIDE';
|
div.textContent='TERSEMBUNYI';
|
||||||
} else {
|
} else {
|
||||||
div.className = 'card' + ((c.suit === '♥' || c.suit === '♦') ? ' red' : '');
|
|
||||||
const top = document.createElement('div');
|
const top = document.createElement('div');
|
||||||
const bot = document.createElement('div');
|
|
||||||
|
|
||||||
top.textContent = c.rank + ' ' + c.suit;
|
top.textContent = c.rank + ' ' + c.suit;
|
||||||
|
const bot = document.createElement('div');
|
||||||
|
bot.style.alignSelf='flex-end';
|
||||||
bot.textContent = c.rank + ' ' + c.suit;
|
bot.textContent = c.rank + ' ' + c.suit;
|
||||||
bot.style.alignSelf = 'flex-end';
|
|
||||||
|
|
||||||
div.appendChild(top);
|
div.appendChild(top);
|
||||||
div.appendChild(bot);
|
div.appendChild(bot);
|
||||||
}
|
}
|
||||||
@ -182,219 +92,146 @@ function renderHand(el, hand, hideFirst = false) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
function updateUI(){
|
||||||
// UPDATE UI
|
renderHand(dealerHandEl,dealer,dealerHidden);
|
||||||
// =========================
|
renderHand(playerHandEl,player,false);
|
||||||
function updateUI() {
|
dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: '+handValues(dealer);
|
||||||
renderHand(dealerHandEl, dealer, dealerHidden);
|
playerValueEl.textContent = 'Nilai: '+handValues(player);
|
||||||
renderHand(playerHandEl, player);
|
balanceEl.textContent = balance;
|
||||||
|
currentBetEl.textContent = currentBet;
|
||||||
dealerValueEl.textContent = dealerHidden ? '??' : 'Nilai: ' + handValues(dealer);
|
|
||||||
playerValueEl.textContent = 'Nilai: ' + handValues(player);
|
|
||||||
updateBalanceDisplay();
|
|
||||||
|
|
||||||
if (currentBetEl) currentBetEl.textContent = currentBet.toLocaleString('id-ID');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
function startRound(){
|
||||||
// START ROUND
|
if(inRound) return;
|
||||||
// =========================
|
|
||||||
function startRound() {
|
|
||||||
if (inRound) return;
|
|
||||||
|
|
||||||
const bet = Number(betInput.value);
|
const bet = Number(betInput.value) || 0;
|
||||||
if (bet <= 0) return alert("Masukkan jumlah taruhan!");
|
if(bet <=0 || bet > balance){ alert(' BANK TIDAK CUKUP! '); return; }
|
||||||
if (bet > gameBalance) return alert("BANK TIDAK CUKUP!");
|
|
||||||
|
|
||||||
currentBet = bet;
|
currentBet = bet;
|
||||||
updateGameBalance(bet, 'bet');
|
balance -= bet;
|
||||||
inRound = true;
|
inRound=true;
|
||||||
dealerHidden = true;
|
dealerHidden=true;
|
||||||
setMessage("", "");
|
|
||||||
|
|
||||||
makeDeck();
|
setMessage('', ''); // RESET MESSAGE
|
||||||
shuffle();
|
|
||||||
|
|
||||||
|
makeDeck(); shuffle();
|
||||||
dealer = [deck.pop(), deck.pop()];
|
dealer = [deck.pop(), deck.pop()];
|
||||||
player = [deck.pop(), deck.pop()];
|
player = [deck.pop(), deck.pop()];
|
||||||
|
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
// NATURAL BLACKJACK
|
// NATURAL BLACKJACK
|
||||||
if (handValues(player) === 21) {
|
if(handValues(player)===21){
|
||||||
dealerHidden = false;
|
dealerHidden=false;
|
||||||
updateUI();
|
updateUI();
|
||||||
|
const dealerVal = handValues(dealer);
|
||||||
|
|
||||||
if (handValues(dealer) === 21) {
|
if(dealerVal===21){
|
||||||
updateGameBalance(currentBet, 'refund');
|
balance += currentBet;
|
||||||
setMessage("Tie!", "");
|
setMessage('Tie (seri).', '');
|
||||||
} else {
|
} else {
|
||||||
updateGameBalance(Math.floor(currentBet * 2.5), 'win');
|
const payout = Math.floor(currentBet * 2.5);
|
||||||
setMessage("Blackjack! You win!", "win");
|
balance += payout;
|
||||||
|
setMessage('Blackjack! You Win!', 'win');
|
||||||
}
|
}
|
||||||
|
|
||||||
inRound = false;
|
inRound=false;
|
||||||
currentBet = 0;
|
currentBet=0;
|
||||||
|
updateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
function playerHit(){
|
||||||
// HIT
|
if(!inRound) return;
|
||||||
// =========================
|
|
||||||
function playerHit() {
|
|
||||||
if (!inRound) return;
|
|
||||||
|
|
||||||
player.push(deck.pop());
|
player.push(deck.pop());
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if (handValues(player) > 21) {
|
if(handValues(player) > 21){
|
||||||
dealerHidden = false;
|
dealerHidden=false;
|
||||||
setMessage("Bust! You Lose!", "lose");
|
setMessage('Bust! You Lose!', 'lose');
|
||||||
inRound = false;
|
inRound=false;
|
||||||
currentBet = 0;
|
currentBet=0;
|
||||||
|
updateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
function playerStand(){
|
||||||
// STAND
|
if(!inRound) return;
|
||||||
// =========================
|
|
||||||
function playerStand() {
|
|
||||||
if (!inRound) return;
|
|
||||||
|
|
||||||
dealerHidden = false;
|
dealerHidden=false;
|
||||||
|
|
||||||
while (handValues(dealer) < 17) dealer.push(deck.pop());
|
while(handValues(dealer)<17){
|
||||||
|
dealer.push(deck.pop());
|
||||||
updateUI();
|
}
|
||||||
|
|
||||||
const pv = handValues(player);
|
const pv = handValues(player);
|
||||||
const dv = handValues(dealer);
|
const dv = handValues(dealer);
|
||||||
|
|
||||||
if (dv > 21 || pv > dv) {
|
if(dv>21 || pv>dv){
|
||||||
updateGameBalance(currentBet * 2, 'win');
|
balance += currentBet*2;
|
||||||
setMessage("You Win!", "win");
|
setMessage('You Win!', 'win');
|
||||||
} else if (pv === dv) {
|
|
||||||
updateGameBalance(currentBet, 'refund');
|
} else if(pv===dv){
|
||||||
setMessage("Tie!", "");
|
balance += currentBet;
|
||||||
|
setMessage('Tie (seri).', '');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
setMessage("You Lose!", "lose");
|
setMessage('You Lose!', 'lose');
|
||||||
}
|
}
|
||||||
|
|
||||||
inRound = false;
|
inRound=false;
|
||||||
currentBet = 0;
|
currentBet=0;
|
||||||
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
function playerDouble(){
|
||||||
// DOUBLE
|
if(!inRound) return;
|
||||||
// =========================
|
if(balance < currentBet){ alert('Bank tidak cukup untuk double.'); return; }
|
||||||
function playerDouble() {
|
|
||||||
if (!inRound) return;
|
|
||||||
if (gameBalance < currentBet) return alert("Bank tidak cukup untuk double.");
|
|
||||||
|
|
||||||
updateGameBalance(currentBet, 'bet');
|
balance -= currentBet;
|
||||||
currentBet *= 2;
|
currentBet *= 2;
|
||||||
|
|
||||||
player.push(deck.pop());
|
player.push(deck.pop());
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if (handValues(player) > 21) {
|
if(handValues(player)>21){
|
||||||
dealerHidden = false;
|
dealerHidden=false;
|
||||||
setMessage("Bust! You Lose!", "lose");
|
setMessage('Bust! You Lose!', 'lose');
|
||||||
inRound = false;
|
inRound=false;
|
||||||
currentBet = 0;
|
currentBet=0;
|
||||||
|
updateUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerStand();
|
playerStand();
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================
|
// EVENTS
|
||||||
// TOP UP MODAL
|
|
||||||
// =========================
|
|
||||||
topupBtn.addEventListener('click', () => {
|
|
||||||
topupModal.style.display = 'flex';
|
|
||||||
topupForm.reset();
|
|
||||||
topupMessage.style.display = 'none';
|
|
||||||
updateBalanceDisplay();
|
|
||||||
});
|
|
||||||
|
|
||||||
function closeTopUpModal() {
|
|
||||||
topupModal.style.display = 'none';
|
|
||||||
topupMessage.style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('click', e => {
|
|
||||||
if (e.target === topupModal) closeTopUpModal();
|
|
||||||
});
|
|
||||||
|
|
||||||
function setModalAmount(amount) {
|
|
||||||
modalAmount.value = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showTopUpMessage(msg, type) {
|
|
||||||
topupMessage.textContent = msg;
|
|
||||||
topupMessage.className = 'topup-message ' + type;
|
|
||||||
topupMessage.style.display = 'block';
|
|
||||||
}
|
|
||||||
|
|
||||||
topupForm.addEventListener('submit', e => {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
const bankMethod = document.querySelector('input[name="bank_method"]:checked');
|
|
||||||
const amount = parseInt(modalAmount.value);
|
|
||||||
|
|
||||||
if (!bankMethod) return showTopUpMessage("Pilih metode pembayaran!", "error");
|
|
||||||
if (amount <= 0 || amount > 1000000) return showTopUpMessage("Jumlah harus 1–1.000.000", "error");
|
|
||||||
|
|
||||||
const formData = new FormData(topupForm);
|
|
||||||
formData.append('userId', userId);
|
|
||||||
|
|
||||||
fetch('process_topup.php', { method: 'POST', body: formData })
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
gameBalance = data.new_balance;
|
|
||||||
updateBalanceDisplay();
|
|
||||||
showTopUpMessage("✓ Top up berhasil!", "success");
|
|
||||||
setTimeout(closeTopUpModal, 2000);
|
|
||||||
} else {
|
|
||||||
showTopUpMessage(data.message, "error");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => showTopUpMessage("Terjadi kesalahan.", "error"));
|
|
||||||
});
|
|
||||||
|
|
||||||
// =========================
|
|
||||||
// EVENT LISTENERS
|
|
||||||
// =========================
|
|
||||||
betBtn.addEventListener('click', startRound);
|
betBtn.addEventListener('click', startRound);
|
||||||
hitBtn.addEventListener('click', playerHit);
|
hitBtn.addEventListener('click', playerHit);
|
||||||
standBtn.addEventListener('click', playerStand);
|
standBtn.addEventListener('click', playerStand);
|
||||||
doubleBtn.addEventListener('click', playerDouble);
|
doubleBtn.addEventListener('click', playerDouble);
|
||||||
|
|
||||||
newRoundBtn.addEventListener('click', () => {
|
newRoundBtn.addEventListener('click', ()=>{
|
||||||
if (inRound && !confirm("Masih dalam ronde. Reset?")) return;
|
if(inRound && !confirm('Masih dalam ronde. Reset?')) return;
|
||||||
|
balance = 1000;
|
||||||
dealer = [];
|
currentBet=0;
|
||||||
player = [];
|
inRound=false;
|
||||||
deck = [];
|
dealer=[];
|
||||||
inRound = false;
|
player=[];
|
||||||
dealerHidden = true;
|
deck=[];
|
||||||
currentBet = 0;
|
dealerHidden=true;
|
||||||
|
setMessage('Bank di-reset.', '');
|
||||||
setMessage("Game di-reset.", "");
|
|
||||||
updateUI();
|
updateUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('keydown', e => {
|
// KEYBOARD
|
||||||
if (e.key === 'h') playerHit();
|
window.addEventListener('keydown', e=>{
|
||||||
if (e.key === 's') playerStand();
|
if(e.key==='h') playerHit();
|
||||||
if (e.key === 'd') playerDouble();
|
if(e.key==='s') playerStand();
|
||||||
if (e.key === 'Enter') startRound();
|
if(e.key==='d') playerDouble();
|
||||||
|
if(e.key==='Enter') startRound();
|
||||||
});
|
});
|
||||||
|
|
||||||
// =========================
|
updateUI();
|
||||||
// INIT
|
|
||||||
// =========================
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
updateBalanceDisplay();
|
|
||||||
});
|
|
||||||
|
|||||||
255
register.php
255
register.php
@ -1,178 +1,141 @@
|
|||||||
<?php
|
<?php
|
||||||
include "koneksi.php";
|
include 'koneksi.php';
|
||||||
session_start();
|
|
||||||
|
|
||||||
/* ==========================================================
|
$success = false;
|
||||||
======================= LOGIN ============================
|
|
||||||
========================================================== */
|
|
||||||
|
|
||||||
$error = "";
|
|
||||||
if (isset($_POST['login'])) {
|
|
||||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
|
||||||
$password = $_POST['password'];
|
|
||||||
|
|
||||||
// PENTING: ambil kolom bank, bukan balance
|
|
||||||
$sql = "SELECT id, username, password, bank FROM users WHERE username = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
|
|
||||||
if (mysqli_num_rows($result) > 0) {
|
|
||||||
$user = mysqli_fetch_assoc($result);
|
|
||||||
|
|
||||||
if ($password === $user['password']) {
|
|
||||||
|
|
||||||
// Set SESSION
|
|
||||||
$_SESSION['user_id'] = $user['id'];
|
|
||||||
$_SESSION['username'] = $user['username'];
|
|
||||||
$_SESSION['bank'] = intval($user['bank']); // PASTIKAN integer
|
|
||||||
|
|
||||||
// Update last login
|
|
||||||
$update_sql = "UPDATE users SET last_login = NOW() WHERE id = ?";
|
|
||||||
$update_stmt = mysqli_prepare($conn, $update_sql);
|
|
||||||
mysqli_stmt_bind_param($update_stmt, "i", $user['id']);
|
|
||||||
mysqli_stmt_execute($update_stmt);
|
|
||||||
|
|
||||||
// Masuk ke game page
|
|
||||||
header("Location: html.php");
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
$error = "Invalid username or password";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$error = "Invalid username or password";
|
|
||||||
}
|
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================
|
|
||||||
======================= REGISTER ==========================
|
|
||||||
========================================================== */
|
|
||||||
|
|
||||||
$success = "";
|
|
||||||
if (isset($_POST['register'])) {
|
if (isset($_POST['register'])) {
|
||||||
|
$username = $_POST['username'];
|
||||||
$username = mysqli_real_escape_string($conn, $_POST['username']);
|
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
$confirm = $_POST['confirm_password'];
|
|
||||||
|
|
||||||
if (empty($username) || empty($password)) {
|
// basic escaping to avoid simple injection (keep consistent with existing style)
|
||||||
$error = "All fields are required.";
|
$username = mysqli_real_escape_string($conn, $username);
|
||||||
} elseif ($password !== $confirm) {
|
$password = mysqli_real_escape_string($conn, $password);
|
||||||
$error = "Passwords do not match.";
|
|
||||||
} elseif (strlen($password) < 6) {
|
|
||||||
$error = "Password must be at least 6 characters.";
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// cek username sudah ada
|
// insert with initial balance = 0
|
||||||
$check_sql = "SELECT id FROM users WHERE username = ?";
|
$SQL = "INSERT INTO users (username, password, balance) VALUES ('$username', '$password', 0)";
|
||||||
$check_stmt = mysqli_prepare($conn, $check_sql);
|
$result = mysqli_query($conn, $SQL);
|
||||||
mysqli_stmt_bind_param($check_stmt, "s", $username);
|
|
||||||
mysqli_stmt_execute($check_stmt);
|
|
||||||
mysqli_stmt_store_result($check_stmt);
|
|
||||||
|
|
||||||
if (mysqli_stmt_num_rows($check_stmt) > 0) {
|
if ($result) {
|
||||||
$error = "Username already exists.";
|
$success = true;
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// simpan password plain text (testing)
|
|
||||||
$hashed = $password;
|
|
||||||
|
|
||||||
// Insert user baru — gunakan kolom bank!
|
|
||||||
$insert_sql = "INSERT INTO users (username, password, bank, created_at)
|
|
||||||
VALUES (?, ?, 1000, NOW())";
|
|
||||||
$insert_stmt = mysqli_prepare($conn, $insert_sql);
|
|
||||||
mysqli_stmt_bind_param($insert_stmt, "ss", $username, $hashed);
|
|
||||||
|
|
||||||
if (mysqli_stmt_execute($insert_stmt)) {
|
|
||||||
|
|
||||||
$success = "Registration successful. You may login.";
|
|
||||||
|
|
||||||
// Auto-login
|
|
||||||
$new_id = mysqli_insert_id($conn);
|
|
||||||
$_SESSION['user_id'] = $new_id;
|
|
||||||
$_SESSION['username'] = $username;
|
|
||||||
$_SESSION['bank'] = 1000;
|
|
||||||
|
|
||||||
header("Location: html.php");
|
|
||||||
exit;
|
|
||||||
} else {
|
|
||||||
$error = "Registration failed. Try again.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>Login / Register</title>
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>OCA Gaming Hub - Login</title>
|
||||||
<link rel="stylesheet" href="login.css">
|
<link rel="stylesheet" href="login.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="logo">
|
||||||
|
<h1>♠ OCA GAMING HUB ♠</h1>
|
||||||
|
<p>BLACKJACK 21 CARD GAME</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="logo">
|
<div class="form-container">
|
||||||
<h1>OCAGamingHub</h1>
|
<div class="card-icon">🂡</div>
|
||||||
<p>Sign in or create account</p>
|
|
||||||
|
<?php if ($success): ?>
|
||||||
|
<div class="success-message show">Register Success!</div>
|
||||||
|
<script>
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.href = 'loginn.php';
|
||||||
|
}, 2000);
|
||||||
|
</script>
|
||||||
|
<?php else: ?>
|
||||||
|
<!-- Sign Up Page -->
|
||||||
|
<form action ="register.php" method="POST">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input id="username" type="text" name="username" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input id="password" type="password" name="password" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button-group">
|
||||||
|
<button type="submit" name="register" class="btn btn-register">Register</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-container">
|
<script>
|
||||||
|
function goToMain() {
|
||||||
|
document.getElementById('mainPage').style.display = 'block';
|
||||||
|
document.getElementById('signupForm').style.display = 'none';
|
||||||
|
// Clear messages
|
||||||
|
document.getElementById('mainMessage').classList.remove('show');
|
||||||
|
document.getElementById('mainError').classList.remove('show');
|
||||||
|
}
|
||||||
|
|
||||||
<?php if (!empty($error)): ?>
|
function goToSignUp() {
|
||||||
<div class="error-message show"><?= htmlspecialchars($error) ?></div>
|
document.getElementById('mainPage').style.display = 'none';
|
||||||
<?php endif; ?>
|
document.getElementById('signupForm').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
<?php if (!empty($success)): ?>
|
// Login handler: validate input and show messages
|
||||||
<div class="success-message show"><?= htmlspecialchars($success) ?></div>
|
function handleLogin() {
|
||||||
<?php endif; ?>
|
const username = document.getElementById('mainUsername').value.trim();
|
||||||
|
const password = document.getElementById('mainPassword').value.trim();
|
||||||
|
const successEl = document.getElementById('mainMessage');
|
||||||
|
const errorEl = document.getElementById('mainError');
|
||||||
|
|
||||||
<!-- ================== LOGIN FORM ================== -->
|
// Reset messages
|
||||||
<form method="POST">
|
successEl.classList.remove('show');
|
||||||
<h2>Login</h2>
|
errorEl.classList.remove('show');
|
||||||
<div class="form-group">
|
|
||||||
<label>Username</label>
|
|
||||||
<input type="text" name="username">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
if (!username || !password) {
|
||||||
<label>Password</label>
|
errorEl.textContent = 'Please enter both username and password.';
|
||||||
<input type="password" name="password">
|
errorEl.classList.add('show');
|
||||||
</div>
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
<button type="submit" name="login" class="btn btn-signin">Login</button>
|
// Simulate login (replace with real auth as needed)
|
||||||
</form>
|
if (username.toLowerCase() === 'admin' && password === 'admin') {
|
||||||
|
successEl.textContent = `Welcome back, ${username}! Redirecting...`;
|
||||||
|
successEl.classList.add('show');
|
||||||
|
setTimeout(() => {
|
||||||
|
alert('Logged in as ' + username + '. (Simulated)');
|
||||||
|
// Example: redirect to game/dashboard page
|
||||||
|
// window.location.href = 'dashboard.html';
|
||||||
|
}, 800);
|
||||||
|
} else {
|
||||||
|
errorEl.textContent = 'Invalid username or password.';
|
||||||
|
errorEl.classList.add('show');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
<hr>
|
// Signup Form Handler
|
||||||
|
document.getElementById('signupForm').addEventListener('submit', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const username = document.getElementById('signupUsername').value;
|
||||||
|
const email = document.getElementById('signupEmail').value;
|
||||||
|
const password = document.getElementById('signupPassword').value;
|
||||||
|
|
||||||
<!-- ================== REGISTER FORM ================== -->
|
if (username && email && password) {
|
||||||
<form method="POST">
|
const message = document.getElementById('signupMessage');
|
||||||
<h2>Register</h2>
|
message.textContent = `✓ Account created successfully for ${username}!`;
|
||||||
|
message.classList.add('show');
|
||||||
|
|
||||||
<div class="form-group">
|
setTimeout(() => {
|
||||||
<label>Username</label>
|
alert(`Account created!\nUsername: ${username}\nEmail: ${email}`);
|
||||||
<input type="text" name="username">
|
// Add your redirect here
|
||||||
</div>
|
goToMain();
|
||||||
|
}, 1500);
|
||||||
<div class="form-group">
|
}
|
||||||
<label>Password</label>
|
});
|
||||||
<input type="password" name="password">
|
</script>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Confirm Password</label>
|
|
||||||
<input type="password" name="confirm_password">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" name="register" class="btn btn-signup">Create Account</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
35
savebank.php
35
savebank.php
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
// save_bank.php
|
|
||||||
session_start();
|
|
||||||
include "koneksi.php";
|
|
||||||
|
|
||||||
// Pastikan user sudah login
|
|
||||||
if (!isset($_SESSION['user_id'])) {
|
|
||||||
die("Not logged in");
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_id = $_SESSION['user_id'];
|
|
||||||
$amount = intval($_POST['amount']); // jumlah top up / perubahan saldo
|
|
||||||
|
|
||||||
// Ambil saldo awal dari database
|
|
||||||
$sql = "SELECT bank FROM users WHERE id = ?";
|
|
||||||
$stmt = mysqli_prepare($conn, $sql);
|
|
||||||
mysqli_stmt_bind_param($stmt, "i", $user_id);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
|
||||||
$user = mysqli_fetch_assoc($result);
|
|
||||||
|
|
||||||
$current_bank = intval($user['bank']);
|
|
||||||
$new_bank = $current_bank + $amount;
|
|
||||||
|
|
||||||
// Update saldo ke database
|
|
||||||
$update_sql = "UPDATE users SET bank = ? WHERE id = ?";
|
|
||||||
$update_stmt = mysqli_prepare($conn, $update_sql);
|
|
||||||
mysqli_stmt_bind_param($update_stmt, "ii", $new_bank, $user_id);
|
|
||||||
mysqli_stmt_execute($update_stmt);
|
|
||||||
|
|
||||||
// Update session biar realtime
|
|
||||||
$_SESSION['bank'] = $new_bank;
|
|
||||||
|
|
||||||
// Kirim respon
|
|
||||||
echo "SUCCESS:".$new_bank;
|
|
||||||
389
topup.php
389
topup.php
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
include 'koneksi.php';
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
if (!isset($_SESSION['username'])) {
|
if (!isset($_SESSION['username'])) {
|
||||||
@ -6,382 +7,60 @@ if (!isset($_SESSION['username'])) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize balance if not set
|
|
||||||
if (!isset($_SESSION['balance'])) {
|
|
||||||
$_SESSION['balance'] = 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
$message_type = '';
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$bank_method = isset($_POST['bank_method']) ? $_POST['bank_method'] : '';
|
|
||||||
$amount = isset($_POST['amount']) ? (int)$_POST['amount'] : 0;
|
$amount = isset($_POST['amount']) ? (int)$_POST['amount'] : 0;
|
||||||
|
|
||||||
if ($amount <= 0) {
|
if ($amount <= 0) {
|
||||||
$message = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
$message = 'Masukkan jumlah top up yang valid (lebih dari 0).';
|
||||||
$message_type = 'error';
|
|
||||||
} elseif (empty($bank_method)) {
|
|
||||||
$message = 'Pilih metode pembayaran terlebih dahulu.';
|
|
||||||
$message_type = 'error';
|
|
||||||
} else {
|
} else {
|
||||||
// Add balance to session
|
$username = mysqli_real_escape_string($conn, $_SESSION['username']);
|
||||||
$_SESSION['balance'] += $amount;
|
// Update balance in DB
|
||||||
$message = 'Top up berhasil! Saldo Anda: Rp ' . number_format($_SESSION['balance'], 0, ',', '.');
|
$update = mysqli_query($conn, "UPDATE users SET balance = balance + $amount WHERE username = '$username'");
|
||||||
$message_type = 'success';
|
if ($update) {
|
||||||
|
// Fetch new balance
|
||||||
|
$res = mysqli_query($conn, "SELECT balance FROM users WHERE username = '$username'");
|
||||||
|
if ($res && mysqli_num_rows($res) > 0) {
|
||||||
|
$row = mysqli_fetch_assoc($res);
|
||||||
|
$_SESSION['balance'] = (int)$row['balance'];
|
||||||
|
$message = 'Top up berhasil. Saldo sekarang: ' . $_SESSION['balance'];
|
||||||
|
} else {
|
||||||
|
$message = 'Top up berhasil, tetapi gagal mengambil saldo terbaru.';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = 'Gagal memproses top up. Coba lagi.';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="id">
|
<html lang="id">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<title>Top Up Saldo - OCA GameHub</title>
|
<title>Top Up - OCA GameHub</title>
|
||||||
<link rel="stylesheet" href="login.css" />
|
<link rel="stylesheet" href="login.css" />
|
||||||
<style>
|
|
||||||
.topup-container {
|
|
||||||
position: relative;
|
|
||||||
z-index: 10;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 600px;
|
|
||||||
padding: 20px;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topup-header {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topup-header h1 {
|
|
||||||
color: #00FF00;
|
|
||||||
font-size: 28px;
|
|
||||||
text-shadow: 0 0 20px rgba(0, 255, 0, 0.6);
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-info {
|
|
||||||
background: rgba(0, 100, 0, 0.3);
|
|
||||||
border: 1px solid rgba(0, 255, 0, 0.3);
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-row {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
color: #88FF88;
|
|
||||||
margin: 8px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.balance-display {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #00FF00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-methods {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
|
||||||
gap: 12px;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-option {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-option input[type="radio"] {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-label {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
padding: 15px;
|
|
||||||
background: rgba(0, 100, 0, 0.2);
|
|
||||||
border: 2px solid rgba(0, 255, 0, 0.3);
|
|
||||||
border-radius: 8px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
color: #88FF88;
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-option input[type="radio"]:checked + .bank-label {
|
|
||||||
background: rgba(0, 255, 0, 0.3);
|
|
||||||
border-color: #00FF00;
|
|
||||||
box-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
|
|
||||||
color: #00FF00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-label:hover {
|
|
||||||
background: rgba(0, 150, 0, 0.2);
|
|
||||||
border-color: rgba(0, 255, 0, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
.bank-icon {
|
|
||||||
font-size: 24px;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.topup-form {
|
|
||||||
background: rgba(0, 100, 0, 0.2);
|
|
||||||
backdrop-filter: blur(10px);
|
|
||||||
border: 2px solid rgba(0, 255, 0, 0.4);
|
|
||||||
border-radius: 15px;
|
|
||||||
padding: 30px;
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 255, 0, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-section {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-section label {
|
|
||||||
display: block;
|
|
||||||
color: #00FF00;
|
|
||||||
font-size: 13px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
letter-spacing: 0.5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-section input {
|
|
||||||
width: 100%;
|
|
||||||
padding: 12px;
|
|
||||||
border: 1px solid rgba(0, 255, 0, 0.5);
|
|
||||||
background: rgba(0, 100, 0, 0.1);
|
|
||||||
color: #88FF88;
|
|
||||||
border-radius: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-section input::placeholder {
|
|
||||||
color: rgba(136, 255, 136, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.form-section input:focus {
|
|
||||||
outline: none;
|
|
||||||
border-color: #00FF00;
|
|
||||||
background: rgba(0, 150, 0, 0.2);
|
|
||||||
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.quick-amounts {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(3, 1fr);
|
|
||||||
gap: 8px;
|
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount-btn {
|
|
||||||
padding: 8px;
|
|
||||||
background: rgba(0, 255, 0, 0.2);
|
|
||||||
border: 1px solid rgba(0, 255, 0, 0.4);
|
|
||||||
color: #00FF00;
|
|
||||||
border-radius: 6px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 12px;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount-btn:hover {
|
|
||||||
background: rgba(0, 255, 0, 0.3);
|
|
||||||
border-color: #00FF00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-success {
|
|
||||||
background: rgba(0, 255, 0, 0.2);
|
|
||||||
border: 1px solid #00FF00;
|
|
||||||
color: #00FF00;
|
|
||||||
padding: 12px;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
font-size: 13px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-success.show {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-error {
|
|
||||||
background: rgba(255, 107, 107, 0.2);
|
|
||||||
border: 1px solid #FF6B6B;
|
|
||||||
color: #FF9999;
|
|
||||||
padding: 12px;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
font-size: 13px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message-error.show {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-group {
|
|
||||||
display: flex;
|
|
||||||
gap: 10px;
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
padding: 12px;
|
|
||||||
border: none;
|
|
||||||
border-radius: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
letter-spacing: 1px;
|
|
||||||
flex: 1;
|
|
||||||
text-decoration: none;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-topup {
|
|
||||||
background: linear-gradient(135deg, #00FF00, #00CC00);
|
|
||||||
color: #000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-topup:hover {
|
|
||||||
transform: translateY(-2px);
|
|
||||||
box-shadow: 0 6px 20px rgba(0, 255, 0, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-back {
|
|
||||||
background: rgba(0, 255, 0, 0.2);
|
|
||||||
color: #00FF00;
|
|
||||||
border: 1px solid #00FF00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-back:hover {
|
|
||||||
background: rgba(0, 255, 0, 0.3);
|
|
||||||
box-shadow: 0 4px 15px rgba(0, 255, 0, 0.4);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="topup-container">
|
<div class="container">
|
||||||
<div class="topup-header">
|
<h2>Top Up Saldo</h2>
|
||||||
<h1>💳 Top Up Saldo</h1>
|
<p>Pengguna: <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong></p>
|
||||||
<p style="color: #88FF88; font-size: 12px;">Pilih metode pembayaran bank Anda</p>
|
<p>Saldo saat ini: <strong><?php echo isset($_SESSION['balance']) ? (int)$_SESSION['balance'] : 0; ?></strong></p>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="user-info">
|
<?php if ($message): ?>
|
||||||
<div class="info-row">
|
<div class="success-message show"><?php echo htmlspecialchars($message); ?></div>
|
||||||
<span>Pemain:</span>
|
<?php endif; ?>
|
||||||
<strong style="color: #00FF00;"><?php echo htmlspecialchars($_SESSION['username']); ?></strong>
|
|
||||||
|
<form method="POST" action="topup.php">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="amount">Jumlah Top Up (angka):</label>
|
||||||
|
<input id="amount" name="amount" type="number" min="1" required />
|
||||||
</div>
|
</div>
|
||||||
<div class="info-row">
|
<div class="button-group">
|
||||||
<span>Saldo Saat Ini:</span>
|
<button type="submit" class="btn btn-register">Top Up</button>
|
||||||
<span class="balance-display" id="topup-balance">Rp <?php echo number_format((int)$_SESSION['balance'], 0, ',', '.'); ?></span>
|
<a href="html.php" class="btn btn-signin">Kembali</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
|
|
||||||
<div class="topup-form">
|
|
||||||
<?php if ($message): ?>
|
|
||||||
<div class="message-<?php echo $message_type; ?> show">
|
|
||||||
<?php echo htmlspecialchars($message); ?>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<form method="POST" action="topup.php">
|
|
||||||
<div class="form-section">
|
|
||||||
<label>🏦 Pilih Bank</label>
|
|
||||||
<div class="bank-methods">
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-bca" name="bank_method" value="bca" required />
|
|
||||||
<label for="bank-bca" class="bank-label">
|
|
||||||
<div class="bank-icon">🏛️</div>
|
|
||||||
<div>BCA</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-mandiri" name="bank_method" value="mandiri" />
|
|
||||||
<label for="bank-mandiri" class="bank-label">
|
|
||||||
<div class="bank-icon">🏦</div>
|
|
||||||
<div>Mandiri</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-bni" name="bank_method" value="bni" />
|
|
||||||
<label for="bank-bni" class="bank-label">
|
|
||||||
<div class="bank-icon">🏤</div>
|
|
||||||
<div>BNI</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-cimb" name="bank_method" value="cimb" />
|
|
||||||
<label for="bank-cimb" class="bank-label">
|
|
||||||
<div class="bank-icon">💰</div>
|
|
||||||
<div>CIMB Niaga</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-ocbc" name="bank_method" value="ocbc" />
|
|
||||||
<label for="bank-ocbc" class="bank-label">
|
|
||||||
<div class="bank-icon">🏢</div>
|
|
||||||
<div>OCBC NISP</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="bank-option">
|
|
||||||
<input type="radio" id="bank-doku" name="bank_method" value="doku" />
|
|
||||||
<label for="bank-doku" class="bank-label">
|
|
||||||
<div class="bank-icon">📱</div>
|
|
||||||
<div>e-Wallet</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-section">
|
|
||||||
<label for="amount">💵 Jumlah Top Up</label>
|
|
||||||
<input id="amount" name="amount" type="number" min="1" placeholder="Contoh: 50000" required />
|
|
||||||
<div class="quick-amounts">
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(10000)">Rp 10K</button>
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(50000)">Rp 50K</button>
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(100000)">Rp 100K</button>
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(250000)">Rp 250K</button>
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(500000)">Rp 500K</button>
|
|
||||||
<button type="button" class="amount-btn" onclick="setAmount(1000000)">Rp 1JT</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="button-group">
|
|
||||||
<button type="submit" class="btn btn-topup">Lanjutkan Top Up</button>
|
|
||||||
<a href="html.php" class="btn btn-back">Kembali</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function setAmount(amount) {
|
|
||||||
document.getElementById('amount').value = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update balance display on page load
|
|
||||||
const serverBalance = <?php echo (int)$_SESSION['balance']; ?>;
|
|
||||||
document.getElementById('topup-balance').textContent = 'Rp ' + serverBalance.toLocaleString('id-ID', {
|
|
||||||
minimumFractionDigits: 0,
|
|
||||||
maximumFractionDigits: 0
|
|
||||||
});
|
|
||||||
localStorage.setItem('playerBalance', serverBalance);
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
22
users.sql
22
users.sql
@ -1,22 +0,0 @@
|
|||||||
-- ==========================================
|
|
||||||
-- FIX: TABLE USERS DENGAN KOLOM BANK
|
|
||||||
-- BANK TETAP TERSIMPAN SAAT LOGOUT & LOGIN
|
|
||||||
-- ==========================================
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS users;
|
|
||||||
|
|
||||||
CREATE TABLE users (
|
|
||||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
|
||||||
username VARCHAR(50) UNIQUE NOT NULL,
|
|
||||||
password VARCHAR(255) NOT NULL,
|
|
||||||
bank INT DEFAULT 1000,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
last_login TIMESTAMP NULL DEFAULT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Tambahin contoh user
|
|
||||||
INSERT INTO users (username, password, bank) VALUES
|
|
||||||
('Ody', '123', 1500),
|
|
||||||
('Claudia', '123', 2000),
|
|
||||||
('Alex', '123', 1000);
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user