I want to count online users in my website.
The way which I found in most of the websites is that to insert a new row in a table containing user's IP and visit time and consider an idle time for example 3 minutes and in each visit delete table rows which are for more than 3 minutes ago and to show online users by counting table rows .
The problem is that this approach is not precise, for example an online user could be idle for more than 3 minutes but in this way only users which their last activity on the website is less than 3 minutes are counted. the other problem is that it is possible a user visit site and exit after 1 minute and by this way this users is still counted as online for 3 minutes.
Do you know a more precise way for counting online users?