prepare("SELECT id, password, role_id FROM users WHERE username = :username"); $stmt->bindParam(':username', $username); $stmt->execute(); $user = $stmt->fetch(PDO::FETCH_ASSOC); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $username; $_SESSION['role_id'] = $user['role_id']; // Log attendance $login_time = date('Y-m-d H:i:s'); $ip_address = $_SERVER['REMOTE_ADDR']; $attendance_stmt = $db->prepare("INSERT INTO attendance (user_id, login_time, ip_address) VALUES (:user_id, :login_time, :ip_address)"); $attendance_stmt->bindParam(':user_id', $user['id']); $attendance_stmt->bindParam(':login_time', $login_time); $attendance_stmt->bindParam(':ip_address', $ip_address); $attendance_stmt->execute(); $_SESSION['attendance_id'] = $db->lastInsertId(); header("Location: index.php"); exit(); } else { $error_message = 'Invalid username or password.'; } } } // Fetch header content ob_start(); include 'index.php'; $page_content = ob_get_clean(); // Extract only the
and