<?php
session_start();

// Check if the admin is already logged in
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
    // Redirect to the statistics page
    header('Location: statistics.php');
    exit();
}

// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST['username'];
    $password = $_POST['password'];

    // Replace with your admin username and password
    $admin_username = 'admin';
    $admin_password = 'admin_password';

    // Check admin credentials
    if ($username === $admin_username && $password === $admin_password) {
        // Set a session variable to indicate that the admin is logged in
        $_SESSION['admin_logged_in'] = true;

        // Redirect to the statistics page
        header('Location: statistics.php');
        exit();
    } else {
        echo "Invalid credentials. Please try again.";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="styles.css">
    <title>Admin Login</title>
</head>
<body>
    <div class="form-container">
        <a href="index.php" class="btn btn-success">Home</a>
        <h2>Admin Login</h2>
        <form action="admin.php" method="post">
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" class="form-control" id="username" placeholder="Enter email" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" class="form-control" id="password" placeholder="Password" name="password" required>
            </div>
            <input class="btn btn-primary" type="submit" value="Login">
        </form>
    </div>
</body>
</html>
