How can PHP be used to check if a user has been inactive for a certain amount of time?

To check if a user has been inactive for a certain amount of time in PHP, you can store a timestamp of the user's last activity in a session variable. Then, you can compare the current time with the stored timestamp to determine if the user has been inactive for the specified amount of time.

session_start();

$inactive_time = 60; // 1 minute of inactivity
if(isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity']) > $inactive_time) {
    // User has been inactive for the specified amount of time
    // Perform any necessary actions, such as logging the user out
    session_unset();
    session_destroy();
}

$_SESSION['last_activity'] = time();