How can the session timestamp be stored in the user's session data in PHP to track user activity?

To store the session timestamp in the user's session data in PHP to track user activity, you can set a specific key-value pair in the $_SESSION superglobal array with the current timestamp whenever a user interacts with your website. This timestamp can then be used to track user activity and determine session duration.

// Start the session
session_start();

// Store the current timestamp in the session data
$_SESSION['last_activity'] = time();