Compare commits
2 Commits
fe5344a341
...
a0ebac731d
| Author | SHA1 | Date | |
|---|---|---|---|
| a0ebac731d | |||
| 0a98a57a77 |
46
login.php
46
login.php
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
// Simpan dengan nama file: login.php
|
||||
session_start();
|
||||
require_once "Config.php";
|
||||
|
||||
@ -6,25 +7,34 @@ if(isset($_POST['btn-login'])){
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
// Ambil user berdasarkan username
|
||||
$stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?");
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
// PERBAIKAN 1: Nama tabel disamakan jadi 'users' (pakai s)
|
||||
$stmt = mysqli_prepare($conn, "SELECT * FROM users WHERE username=?");
|
||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||
mysqli_stmt_execute($stmt);
|
||||
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
|
||||
// Kalau username tidak ditemukan ATAU password salah
|
||||
if (!$row || !password_verify($password, $row['password'])) {
|
||||
echo "Username atau password salah";
|
||||
// Kalau username tidak ditemukan ATAU password salah
|
||||
if (!$row || !password_verify($password, $row['password'])) {
|
||||
// PERBAIKAN 2: Pakai Script Alert biar user dikembalikan ke index
|
||||
echo "<script>
|
||||
alert('Username atau Password salah!');
|
||||
window.location.href='index.html';
|
||||
</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Login sukses
|
||||
$_SESSION['username'] = $row['username'];
|
||||
$_SESSION['login'] = true; // Tambahan untuk cek status login nanti
|
||||
|
||||
// PERBAIKAN 3: Arahkan ke file game kamu (sesuaikan nama filenya)
|
||||
// Di screenshot ada mainboard.html, pakai itu.
|
||||
echo "<script>
|
||||
alert('Login Berhasil! Selamat Datang, " . $username . "');
|
||||
window.location.href='mainboard.html';
|
||||
</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Login sukses
|
||||
$_SESSION['username'] = $row['username'];
|
||||
echo "<script>alert('Silakan login.'); window.location.href='mainboard.html';</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
||||
53
register.php
53
register.php
@ -1,49 +1,46 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once "Config.php";
|
||||
// Simpan dengan nama file: register.php
|
||||
include 'Config.php';
|
||||
|
||||
if(isset($_POST['btn-register'])) {
|
||||
if (isset($_POST['btn-register'])) {
|
||||
$username = $_POST['username'];
|
||||
$email = $_POST['email'];
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
$confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT);
|
||||
$confirm = $_POST['confirm_password'];
|
||||
|
||||
if (!$username || !$email || !$password || !$confirmPassword) {
|
||||
echo "<script>alert('Semua field harus diisi'); window.history.back();</script>";
|
||||
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
|
||||
echo "<script>alert('Semua data harus diisi!'); window.location='index.html';</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
echo "<script>alert('Format email tidak valid'); window.history.back();</script>";
|
||||
if ($password !== $confirm) {
|
||||
echo "<script>alert('Password dan Konfirmasi tidak cocok!'); window.location='index.html';</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($password !== $confirmPassword) {
|
||||
echo "<script>alert('Password dan konfirmasi password tidak cocok'); window.history.back();</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strlen($password) < 6) {
|
||||
echo "<script>alert('Password minimal 6 karakter'); window.history.back();</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$stmt = mysqli_prepare($conn, "SELECT id FROM user WHERE username=? OR email=?");
|
||||
// Cek Username/Email di tabel 'users'
|
||||
$stmt = mysqli_prepare($conn, "SELECT id FROM users WHERE username = ? OR email = ?");
|
||||
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
|
||||
mysqli_stmt_execute($stmt);
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
if (mysqli_stmt_num_rows($stmt) > 0) {
|
||||
echo "<script>alert('Username atau email sudah digunakan'); window.history.back();</script>";
|
||||
echo "<script>alert('Username atau Email sudah terpakai!'); window.location='index.html';</script>";
|
||||
exit;
|
||||
}
|
||||
mysqli_stmt_close($stmt);
|
||||
|
||||
$stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')");
|
||||
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
|
||||
echo "<script>alert('Registrasi berhasil! Silakan login.'); window.location.href='login.html';</script>";
|
||||
exit;
|
||||
// Insert ke tabel 'users'
|
||||
$stmtInsert = mysqli_prepare($conn, "INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
|
||||
mysqli_stmt_bind_param($stmtInsert, "sss", $username, $email, $hashed_password);
|
||||
|
||||
if (mysqli_stmt_execute($stmtInsert)) {
|
||||
echo "<script>alert('Registrasi Berhasil! Silakan Login.'); window.location='index.html';</script>";
|
||||
} else {
|
||||
echo "Error: " . mysqli_error($conn);
|
||||
}
|
||||
mysqli_stmt_close($stmtInsert);
|
||||
}
|
||||
?>
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user