What are the different methods to track and display the last 10 visited pages on a website using PHP?

To track and display the last 10 visited pages on a website using PHP, you can utilize sessions to store the visited pages in an array. You can then display the last 10 visited pages by retrieving them from the session array and displaying them in reverse order.

<?php
session_start();

// Track visited pages
if(!isset($_SESSION['visited_pages'])) {
    $_SESSION['visited_pages'] = [];
}

// Add current page to visited pages
$current_page = $_SERVER['REQUEST_URI'];
array_push($_SESSION['visited_pages'], $current_page);

// Limit visited pages to 10
if(count($_SESSION['visited_pages']) > 10) {
    array_shift($_SESSION['visited_pages']);
}

// Display last 10 visited pages
echo "<h2>Last 10 Visited Pages:</h2>";
echo "<ul>";
foreach(array_reverse($_SESSION['visited_pages']) as $page) {
    echo "<li>$page</li>";
}
echo "</ul>";
?>