session_start(); if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > 300)) { // User has been inactive for more than 5 minutes session_destroy(); header("Location: login.php"); } $_SESSION['last_activity'] = time();This code starts a session and checks the user's last activity time. If the user has been inactive for more than 5 minutes, their session is destroyed and they are redirected to the login page. Package library: The code example above uses the PHP session library, which is included in the core PHP distribution. However, there are also many other packages and libraries available for PHP that can be used to implement user active functionality, such as the Symfony HttpFoundation component or the Laravel Session library.