44 lines
1012 B
PHP
44 lines
1012 B
PHP
<?php
|
|
session_start();
|
|
include 'koneksi.php';
|
|
|
|
// Cek apakah form disubmit
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
// Ambil data dari form
|
|
$username = trim($_POST['username'] ?? '');
|
|
$password = trim($_POST['password'] ?? '');
|
|
|
|
// Validasi tidak boleh kosong
|
|
if (empty($username) || empty($password)) {
|
|
header("Location: login.php?error=empty");
|
|
exit;
|
|
}
|
|
|
|
// Cek ke database
|
|
$stmt = $conn->prepare("SELECT * FROM admin WHERE username = ?");
|
|
$stmt->bind_param("s", $username);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if ($result->num_rows > 0) {
|
|
$admin = $result->fetch_assoc();
|
|
|
|
// Cek password
|
|
if ($password === $admin['password']) {
|
|
$_SESSION['login'] = true;
|
|
$_SESSION['username'] = $username;
|
|
|
|
// Redirect ke admin.php
|
|
header("Location: admin.php");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Login gagal
|
|
header("Location: login.php?error=wrong");
|
|
exit;
|
|
?>
|