prepare("SELECT * FROM users WHERE email = :email"); $stmt->execute(['email' => $email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password_hash'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; $_SESSION['role'] = $user['role']; // Redirect to the appropriate dashboard if ($user['role'] === 'admin') { header("Location: admin/index.php"); } else { header("Location: dashboard.php"); } exit(); } else { $errors[] = 'Invalid email or password combination.'; } } catch (PDOException $e) { // For security, don't show detailed DB errors in production error_log("Database error: " . $e->getMessage()); $errors[] = "An internal error occurred. Please try again later."; } } } ?>
Login to access your account and explore the best cars in Afghanistan.
Don't have an account? Create one now.