you could use mysql (or whatever) to flag whether a user is still logged in. It is best to avoid too many queries though. Selecting a flag may not hurt too much depending on traffic.
I have a site that I am trying to minimize SQL queries, so I pass important data in an array. The only problem is that the array is stored in a hidden field, and the back button would see the array before you adjusted it.