PNG IHDR x sBIT|d pHYs + tEXtSoftware www.inkscape.org< ,tEXtComment
<?php
session_start();
// Connect to database (Adjust path to where db.php is located)
require '../db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = trim($_POST['email']);
$password = $_POST['password'];
// 1. Check if user exists AND is an admin
$stmt = $pdo->prepare("SELECT user_id, password_hash, role FROM users WHERE email = ? AND role = 'admin'");
$stmt->execute([$email]);
$user = $stmt->fetch();
// 2. Verify Password
if ($user && password_verify($password, $user['password_hash'])) {
// Success: Set Session Variables
$_SESSION['admin_logged_in'] = true;
$_SESSION['admin_id'] = $user['user_id'];
// Redirect to Dashboard
header('Location: dashboard.php');
exit;
} else {
// Failed: Redirect back to login with error flag
header('Location: login.php?error=1');
exit;
}
} else {
// Direct access not allowed
header('Location: login.php');
exit;
}
?>
b IDATxytVսϓ22 A@IR:hCiZ[v*E:WũZA ^dQeQ @ !jZ'>gsV仿$|?g)&x-E