If a user is logged in, I would normally assign a session id that is then expunged either on logout or after a set time period. You might do it differently.
Either way, there should be something that is different between those who have a current session token and those who don't. Use that to assist your count. If you need to handle large numbers of users, I strongly recommend having a separate table for logged in users, in which case you can simply count the number of rows.
I wonder , how can i add number of online visitors to my site using php and mysql ?
http://lmgtfy.com/?q=php+visitor+counter
How do you currently handle logging in?
If a user is logged in, I would normally assign a session id that is then expunged either on logout or after a set time period. You might do it differently.
Either way, there should be something that is different between those who have a current session token and those who don't. Use that to assist your count. If you need to handle large numbers of users, I strongly recommend having a separate table for logged in users, in which case you can simply count the number of rows.