| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- require_once '../includes/config.php';
- require_once '../includes/database.php';
- require_once '../includes/auth.php';
- $auth = new Auth();
- if ($auth->isLoggedIn()) {
- header('Location: index.php');
- exit;
- }
- $errors = [];
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $username = trim($_POST['username'] ?? '');
- $password = $_POST['password'] ?? '';
-
- if (empty($username) || empty($password)) {
- $errors[] = 'Please enter both username and password';
- } elseif ($auth->login($username, $password)) {
- header('Location: index.php');
- exit;
- } else {
- $errors[] = 'Invalid username or password';
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Admin Login - <?php echo SITE_TITLE; ?></title>
- <link rel="stylesheet" href="../css/style.css">
- </head>
- <body class="login-page">
- <div class="container">
- <div class="login-form">
- <h1>Admin Login</h1>
-
- <?php if (!empty($errors)): ?>
- <div class="alert alert-error">
- <?php foreach ($errors as $error): ?>
- <p><?php echo htmlspecialchars($error); ?></p>
- <?php endforeach; ?>
- </div>
- <?php endif; ?>
-
- <form method="post">
- <div class="form-group">
- <label for="username">Username:</label>
- <input type="text" id="username" name="username" required>
- </div>
-
- <div class="form-group">
- <label for="password">Password:</label>
- <input type="password" id="password" name="password" required>
- </div>
-
- <button type="submit" class="btn btn-primary">Login</button>
- </form>
- </div>
- </div>
- </body>
- </html>
|