session_start(); // --------- CONFIG: change if needed ---------- $ADMIN_USER = 'BalaInfotech'; $ADMIN_PASS = 'BalaInfotech@2025#@'; // Optional: change redirect after login (null = same page) $after_login_redirect = null; // e.g. '/manage.php' or null // -------------------------------------------- // Logout handling if (isset($_GET['auth_action']) && $_GET['auth_action'] === 'logout') { $_SESSION = []; session_destroy(); // redirect to same page without query $loc = strtok($_SERVER['REQUEST_URI'], '?'); header("Location: $loc"); exit; } // If already logged in -> continue if (!empty($_SESSION['auth_logged_in']) && $_SESSION['auth_user'] === $ADMIN_USER) { return; // allow page to render } // Process login form $login_error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['auth_user'], $_POST['auth_pass'])) { $u = trim($_POST['auth_user']); $p = $_POST['auth_pass']; if ($u === $ADMIN_USER && $p === $ADMIN_PASS) { // success $_SESSION['auth_logged_in'] = true; $_SESSION['auth_user'] = $ADMIN_USER; // Redirect to avoid form resubmission if ($after_login_redirect) { header("Location: $after_login_redirect"); exit; } else { $loc = strtok($_SERVER['REQUEST_URI'], '?'); header("Location: $loc"); exit; } } else { $login_error = "Invalid username or password."; } } // If not logged in -> show login form and stop further rendering // (This outputs a minimal Bootstrap-styled login box; you can replace CSS if needed) ?>