// Intercept application submission request if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['trigger_apply'])) { // 1. THE AUTHENTICATION GATEWAY if (!isset($_SESSION['employer_id'])) { // The user is an unauthenticated guest. // We capture their exact current location so we can return them right back here later. $fallback_url = "employers/login.php?redirect=" . urlencode("job-details.php?id=" . $job_id); echo ""; exit; } // 2. THE DUPLICATE PROTECTION GUARD if (!$has_applied) { try { // Save application vector to the database tracking matrix $apply_stmt = $pdo->prepare("INSERT INTO applications (vacancy_id, employer_id, status) VALUES (?, ?, 'Submitted')"); $apply_stmt->execute([$job_id, $_SESSION['employer_id']]); // Set state to true to instantly mutate the UI interface state $has_applied = true; $message = "