What are alternative methods to using cookies for tracking user activity on a website?

Using cookies for tracking user activity on a website can raise privacy concerns and may not be effective if users disable cookies in their browsers. An alternative method is to use session variables in PHP to track user activity during their visit to the website. Session variables store data on the server side and can be accessed throughout the user's session.

// Start or resume a session
session_start();

// Track user activity by setting session variables
$_SESSION['last_activity'] = time();
$_SESSION['page_views'] = isset($_SESSION['page_views']) ? $_SESSION['page_views'] + 1 : 1;

// Display the number of page views
echo "Page views: " . $_SESSION['page_views'];