Link to home
Start Free TrialLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

Vb - Count users on page

Hey guys,

Im creating a forum in vb (visual studio) and want to know how i can get no of users on the page.

I know you can use Membership.GetNumberOfUsersOnline() to get users online but i want to find how many are viewing a page.
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

This can be quite tricky. How do you know when someone is still on the page? Someone might have visited the page and immediately closed their browser... how will you know that they are no longer on the page? Or if they navigate onto another page... how will you know?

One mechanism you can consider is to generate a serial number (maybe using a GUID string), then have a Javascript that polls the server every few seconds (say every 3 seconds) and all that it does is to send back that same GUID to the server. On the server, you can perhaps have a DataTable in which you store the GUID and the last time you "heard" from that GUID... You can regularly clear out (from the datatable) any GUID values that havent "spoken" to the server in say 10 seconds... A count of the number of rows in that DataTable then becomes the number of people still on the page (relatively accurate within the last 4-6 seconds). It is very imprecise, but might do the trick...

This mechanism is also not without problems, for the number of connections that it opens and closes every so often with the server. Have a look at this (for other technical considerations) http://query7.com/avoiding-long-polling

The jQuery snippet below polls the server every 3 seconds for new information and displays it in a simple alert box.

function callComplete(response) {
	alert("Response received is: "+response);
};

function connect() {
	// when the call completes, callComplete() will be called along with
	// the response returned
	$.post('/path/to/script.php', {}, callComplete, 'json');
};

$(document).ready( function() {
	setInterval(connect,3000);
}

Open in new window

Avatar of Member_2_5230414
Member_2_5230414

ASKER

Sounds like a very coplex way about it... as u see on my other question i have been able to record views and delete them on other pages but the whole browser closing is the issue.

It must be done as i have seen it used in other places and i know php can do it very well
my other option is on every page to record the page the user visited last and at what time... then run a query of the page from the last 10 seconds and make anote of that
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial