Compare commits
No commits in common. "a0ebac731d6b471cfcdf414723ffd0cff7cd95c7" and "fe5344a341dfdddb0be267b32849f6281f6bfb6e" have entirely different histories.
a0ebac731d
...
fe5344a341
44
login.php
44
login.php
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
// Simpan dengan nama file: login.php
|
|
||||||
session_start();
|
session_start();
|
||||||
require_once "Config.php";
|
require_once "Config.php";
|
||||||
|
|
||||||
@ -7,34 +6,25 @@ if(isset($_POST['btn-login'])){
|
|||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
|
||||||
// PERBAIKAN 1: Nama tabel disamakan jadi 'users' (pakai s)
|
// Ambil user berdasarkan username
|
||||||
$stmt = mysqli_prepare($conn, "SELECT * FROM users WHERE username=?");
|
$stmt = mysqli_prepare($conn, "SELECT * FROM user 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'])) {
|
||||||
// PERBAIKAN 2: Pakai Script Alert biar user dikembalikan ke index
|
echo "Username atau password salah";
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
51
register.php
51
register.php
@ -1,46 +1,49 @@
|
|||||||
<?php
|
<?php
|
||||||
// Simpan dengan nama file: register.php
|
session_start();
|
||||||
include 'Config.php';
|
require_once "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'];
|
||||||
$confirm = $_POST['confirm_password'];
|
$confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT);
|
||||||
|
|
||||||
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
|
if (!$username || !$email || !$password || !$confirmPassword) {
|
||||||
echo "<script>alert('Semua data harus diisi!'); window.location='index.html';</script>";
|
echo "<script>alert('Semua field harus diisi'); window.history.back();</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($password !== $confirm) {
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
echo "<script>alert('Password dan Konfirmasi tidak cocok!'); window.location='index.html';</script>";
|
echo "<script>alert('Format email tidak valid'); window.history.back();</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek Username/Email di tabel 'users'
|
if ($password !== $confirmPassword) {
|
||||||
$stmt = mysqli_prepare($conn, "SELECT id FROM users WHERE username = ? OR email = ?");
|
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=?");
|
||||||
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 terpakai!'); window.location='index.html';</script>";
|
echo "<script>alert('Username atau email sudah digunakan'); window.history.back();</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
|
||||||
|
|
||||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
$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);
|
||||||
|
|
||||||
// Insert ke tabel 'users'
|
echo "<script>alert('Registrasi berhasil! Silakan login.'); window.location.href='login.html';</script>";
|
||||||
$stmtInsert = mysqli_prepare($conn, "INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
|
exit;
|
||||||
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