You can use a database or file to store the user's IP and last access time. And then check the last access time. If the last access time is less than 15 minutes (or some other number) away from now, then consider the user being 'active'. If the last access time is older than 15 minutes, then erase that entry because the user is considered 'inactive'.
Diego