What are some alternative methods or techniques that can be used to track user activity and login times on a PHP website effectively?

One alternative method to track user activity and login times on a PHP website effectively is to use session variables to store timestamps of user actions. By updating these timestamps on each page load or action, you can track when a user was last active or logged in.

// Start session
session_start();

// Update last activity timestamp
$_SESSION['last_activity'] = time();

// Check if user is logged in
if(isset($_SESSION['user_id'])){
    // Update last login timestamp
    $_SESSION['last_login'] = time();
}