What are the potential drawbacks of updating the last login time of a user every time they visit a page on a PHP website?

Updating the last login time of a user every time they visit a page on a PHP website can lead to unnecessary database writes and potentially slow down the website. To solve this issue, you can implement a check to only update the last login time if a certain amount of time has passed since the last update.

// Check if a certain amount of time has passed since the last login update
if(time() - strtotime($user['last_login']) > 3600) { // Update last login time if more than 1 hour has passed
    // Update last login time in the database
    $query = "UPDATE users SET last_login = NOW() WHERE id = :user_id";
    $stmt = $pdo->prepare($query);
    $stmt->bindParam(':user_id', $user_id);
    $stmt->execute();
}