Click to See Complete Forum and Search --> : Are there any users?


kareem
03-14-2003, 09:19 PM
Hi
Is there a code I can add to my index page that it tells how many users are browsing my website? Will it be possible to incorporate this in a page that is written by HTML?

Thanks

Nedals
03-14-2003, 11:12 PM
Do you mean a hit counter or something like it? If so, that can only be done server-side with some type of script (CGI/Perl, PHP, ASP, etc). I don't know of any way it can be done in HTML.

kareem
03-15-2003, 03:24 AM
No! I mean something that can tell me how many user are currently browsing my site ... not only me any one can see it "who is online?" type thing ,,,,like the one we see here in this forum .. and many other sites...

Alhazred
03-15-2003, 10:10 AM
The HTTP protocol used by the web is a stateless, connectionless protocol. What this means is that each request for a web page has no relationship to anything that came before it, thus the concept of being 'logged in' to a web site is meaningless.

Now, it is possible to have a cookie which tells the web server you are dealing with who you are, or a 'basic auth' token, or something in the query string on the URL you go to (or hidden form field in a form POST) which lets the web application you are dealing with know that you provided a username and password at some earlier time, which is what people mean when they say they are 'logged in to a web site'.

The difference is that because HTTP is connectionless once you grab a page from the web server your browser simply disconnects and goes away. There is NO WAY that the web server can know if you will or will not ever come back, so there is NO WAY it can say that "X users are on this server right now" because there is no concept of being ON the server (IE connected to it) in the world wide web technology.

About all you can do is apply some rule of thumb and say something like 'All the people that have asked for a page and presented a cookie saying they were logged in in the last 30 minutes are "on" the server' or somesuch. When you see web sites that say things like '43 active users' thats what they're doing, just assuming everyone that visited a page in the last X minutes is 'active'.

Any decent web application framework has tools within it which a programmer can use to get that sort of information. Usually each time someone logs in they get a 'session' created for them, which is usually a database entry of some sort. Generally after a set time of inactivity the session will be cleaned out of the database, thus a count of sessions in the database would give you a basis for a count of active users. Other strategies exist as well, it all depends on your application framework.