you simply check if a certain value is still set in the session (and you need to keep track of who's logged in in a database or flat file). As soon as the var is gone, you know the session has expired.
Often a script checks if a certain time has expired (say 10 minutes), and destroys the session itself, instead of the server destroying the session