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
$head_and_header = ''; if (preg_match('/.*?<\/head>/s', $page_content, $head_match)) { $head_and_header .= $head_match[0]; } if (preg_match('/
.*?<\/header>/s', $page_content, $header_match)) { $head_and_header .= $header_match[0]; } // Replace active nav link $head_and_header = str_replace('Home', 'Home', $head_and_header); $head_and_header = preg_replace('//', '', $head_and_header); echo str_replace('', '', $head_and_header); ?>
.*?<\/footer>/s', $page_content, $footer_match)) { echo $footer_match[0]; } ?>