In this example, we first start a PHP session using the session_start() function. We then check if the user ID variable is set in the session. If it is, we retrieve the user ID and do something with it. If it is not set, we redirect the user to the login page. This functionality can be found in a variety of PHP libraries, such as the Laravel framework's authentication system or the Symfony security component.