Hi Anh, assuming that you are using a meta-refresh to refresh the chat page every few seconds/minutes, you can have a data file for each user currently in the chat. Every time the page gets refreshed (which means their chat window is still open) you can touch that file. Then run a cronjob every couple minutes to take out chatters who haven't touched their data file in x minutes or something.
Jay