Compare commits
2 Commits
fe5344a341
...
a0ebac731d
| Author | SHA1 | Date | |
|---|---|---|---|
| a0ebac731d | |||
| 0a98a57a77 |
46
login.php
46
login.php
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Simpan dengan nama file: login.php
|
||||||
session_start();
|
session_start();
|
||||||
require_once "Config.php";
|
require_once "Config.php";
|
||||||
|
|
||||||
@ -6,25 +7,34 @@ if(isset($_POST['btn-login'])){
|
|||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
// Ambil user berdasarkan username
|
// PERBAIKAN 1: Nama tabel disamakan jadi 'users' (pakai s)
|
||||||
$stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?");
|
$stmt = mysqli_prepare($conn, "SELECT * FROM users WHERE username=?");
|
||||||
mysqli_stmt_bind_param($stmt, "s", $username);
|
mysqli_stmt_bind_param($stmt, "s", $username);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
|
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
$row = mysqli_fetch_assoc($result);
|
$row = mysqli_fetch_assoc($result);
|
||||||
|
|
||||||
// Kalau username tidak ditemukan ATAU password salah
|
// Kalau username tidak ditemukan ATAU password salah
|
||||||
if (!$row || !password_verify($password, $row['password'])) {
|
if (!$row || !password_verify($password, $row['password'])) {
|
||||||
echo "Username atau password salah";
|
// 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;
|
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
|
<?php
|
||||||
session_start();
|
// Simpan dengan nama file: register.php
|
||||||
require_once "Config.php";
|
include 'Config.php';
|
||||||
|
|
||||||
if(isset($_POST['btn-register'])) {
|
if (isset($_POST['btn-register'])) {
|
||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$email = $_POST['email'];
|
$email = $_POST['email'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
$confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT);
|
$confirm = $_POST['confirm_password'];
|
||||||
|
|
||||||
if (!$username || !$email || !$password || !$confirmPassword) {
|
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
|
||||||
echo "<script>alert('Semua field harus diisi'); window.history.back();</script>";
|
echo "<script>alert('Semua data harus diisi!'); window.location='index.html';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if ($password !== $confirm) {
|
||||||
echo "<script>alert('Format email tidak valid'); window.history.back();</script>";
|
echo "<script>alert('Password dan Konfirmasi tidak cocok!'); window.location='index.html';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($password !== $confirmPassword) {
|
// Cek Username/Email di tabel 'users'
|
||||||
echo "<script>alert('Password dan konfirmasi password tidak cocok'); window.history.back();</script>";
|
$stmt = mysqli_prepare($conn, "SELECT id FROM users WHERE username = ? OR email = ?");
|
||||||
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=?");
|
|
||||||
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
|
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
mysqli_stmt_store_result($stmt);
|
mysqli_stmt_store_result($stmt);
|
||||||
|
|
||||||
if (mysqli_stmt_num_rows($stmt) > 0) {
|
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;
|
exit;
|
||||||
}
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
|
||||||
$stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')");
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||||
mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash);
|
|
||||||
mysqli_stmt_execute($stmt);
|
|
||||||
|
|
||||||
echo "<script>alert('Registrasi berhasil! Silakan login.'); window.location.href='login.html';</script>";
|
// Insert ke tabel 'users'
|
||||||
exit;
|
$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