/home/awneajlw/public_html/codestechvista.com/admin/login.php
<?php
session_start();
require_once '../config/database.php';
// If already logged in as admin, redirect to dashboard
if (isset($_SESSION['user_id']) && isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin') {
header('Location: dashboard.php');
exit();
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$email = trim($_POST['email']);
$password = $_POST['password'];
if (empty($email) || empty($password)) {
$error = 'Please fill in all fields.';
} else {
$database = new Database();
$db = $database->getConnection();
$query = "SELECT id, name, email, password, role, phone FROM users WHERE email = ? AND role = 'admin'";
$stmt = $db->prepare($query);
$stmt->execute([$email]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password'])) {
// Set session variables
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['name'];
$_SESSION['user_email'] = $user['email'];
$_SESSION['user_role'] = $user['role'];
$_SESSION['user_phone'] = $user['phone'];
$_SESSION['last_activity'] = time();
header('Location: dashboard.php');
exit();
} else {
$error = 'Invalid admin credentials. Please check your email and 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 - OptiSlip</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #169D53 0%, #0d7a3f 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.login-container {
background: white;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
max-width: 450px;
width: 100%;
}
.login-header {
background: linear-gradient(135deg, #169D53 0%, #0d7a3f 100%);
color: white;
padding: 40px 30px;
text-align: center;
}
.login-header i {
font-size: 60px;
margin-bottom: 20px;
opacity: 0.9;
}
.login-header h2 {
font-size: 28px;
font-weight: 700;
margin-bottom: 10px;
}
.login-header p {
font-size: 14px;
opacity: 0.9;
}
.login-body {
padding: 40px 30px;
}
.form-label {
font-weight: 600;
color: #333;
margin-bottom: 8px;
font-size: 14px;
}
.form-control {
padding: 12px 15px;
border: 2px solid #e0e0e0;
border-radius: 10px;
font-size: 15px;
transition: all 0.3s ease;
}
.form-control:focus {
border-color: #169D53;
box-shadow: 0 0 0 0.2rem rgba(22, 157, 83, 0.15);
}
.input-group-text {
background: #f8f9fa;
border: 2px solid #e0e0e0;
border-right: none;
border-radius: 10px 0 0 10px;
color: #169D53;
}
.input-group .form-control {
border-left: none;
border-radius: 0 10px 10px 0;
}
.input-group .form-control:focus {
border-left: none;
}
.btn-login {
background: linear-gradient(135deg, #169D53 0%, #0d7a3f 100%);
border: none;
color: white;
padding: 14px 20px;
border-radius: 10px;
font-weight: 600;
font-size: 16px;
width: 100%;
transition: all 0.3s ease;
margin-top: 10px;
}
.btn-login:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(22, 157, 83, 0.3);
color: white;
}
.alert {
border-radius: 10px;
padding: 15px;
margin-bottom: 20px;
font-size: 14px;
}
.alert-danger {
background: #fee;
border: 1px solid #fcc;
color: #c33;
}
.alert-success {
background: #efe;
border: 1px solid #cfc;
color: #3c3;
}
.login-footer {
text-align: center;
padding: 20px;
background: #f8f9fa;
border-top: 1px solid #e0e0e0;
}
.login-footer a {
color: #169D53;
text-decoration: none;
font-weight: 600;
}
.login-footer a:hover {
text-decoration: underline;
}
.admin-badge {
display: inline-block;
background: rgba(255, 255, 255, 0.2);
padding: 5px 15px;
border-radius: 20px;
font-size: 12px;
margin-top: 10px;
}
@media (max-width: 576px) {
.login-container {
border-radius: 15px;
}
.login-header {
padding: 30px 20px;
}
.login-header h2 {
font-size: 24px;
}
.login-body {
padding: 30px 20px;
}
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-header">
<i class="fas fa-user-shield"></i>
<h2>Admin Panel</h2>
<p>OptiSlip - Optical Shop Management</p>
<span class="admin-badge">Administrator Access Only</span>
</div>
<div class="login-body">
<?php if ($error): ?>
<div class="alert alert-danger">
<i class="fas fa-exclamation-circle"></i> <?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle"></i> <?php echo htmlspecialchars($success); ?>
</div>
<?php endif; ?>
<form method="POST" action="">
<div class="mb-3">
<label for="email" class="form-label">
<i class="fas fa-envelope"></i> Admin Email
</label>
<div class="input-group">
<span class="input-group-text">
<i class="fas fa-user"></i>
</span>
<input type="email" class="form-control" id="email" name="email"
placeholder="admin@eyeclinic.com"
value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>"
required autofocus>
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label">
<i class="fas fa-lock"></i> Password
</label>
<div class="input-group">
<span class="input-group-text">
<i class="fas fa-key"></i>
</span>
<input type="password" class="form-control" id="password" name="password"
placeholder="Enter your password"
required>
</div>
</div>
<button type="submit" class="btn-login">
<i class="fas fa-sign-in-alt"></i> Login to Admin Panel
</button>
</form>
</div>
<div class="login-footer">
<a href="../index.php">
<i class="fas fa-arrow-left"></i> Back to Website
</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>