Heres an idea.
Store your session info in a database.
Create a table called sessions. This table stores a last field and a sessid field. Whenever a new session is created, insert into database
insert into sessions (last,sessid) values (now(),'uniqueid');
Everytime a page is accessed with an existing session id , update their last column to now.
update sessions set last = now() where sessid = 'uniqueid';
Have your sessions expire after a certain time period, so in this case it will be 20 minutes. After 20 minutes of inactivity, that session has expired, and users have to log back in. Have a crontab run every minute that deletes old sessions out of the database.
delete from sessions where last < subdate(now(), interval 20 minute)
Then a rough logged in count would be a simple. If you are looking for an exact number, then my idea sucks.
select count(*) from sessions.