Who Is online

603
South Africa
South Africa
david_perel
How do sites like this and other PHP boards recognise when a user is online?

Does it update a DB which then keeps getting updated everytime the user does something? Or does it use a script?
 
Well i believe it goes a little something like this. Don't quote me on this, the method described is how i expect it to be done, not 100% sure.

Using DB:

You could have a table that keeps track of all the people online, but people would have to log off for the database to see that they've gone online. It wouldn't take into account that you could close the browser to go offline like you can with session values, it would assume you were still online.

Using Script:

When you load a page of the forum for the first time in a session some code adds a 1 to the number of people online and a session value called SessionGuest (for instance) is set on your pc. Whilst that session value is true, you will be considered online and you will not add 1 each time you load a page.

The session gets updated each time you load a page and will timeout after a period of inactivity. When it times out, a 1 is subtracted from the number of people online and your session is set to false.

That would tell you how many people are online. For distinguishing between who's a guest and who's a user i guess you could have a session value that is called SessionUser that is set to true when you log in. And if SessionUser is set to true then SessionGuest is set to false for that person.

Seriously that's a rough guess and probably incorrect, but might work..
 
The way I'm doing it at my site (very slow way but at the mo I have no choice) is to update a DB with your log in time.

I then query the DB with a 'WHERE Time = Now and 5mins earlier.' Then whenever someone goes to a page etc it updates the DB with the latest Active time, so he will appear online for that moment.

Hope that made sense ^.

Now the above way is too slow coz it has to open up a DB and update it. Thats why I want to know if sites like this one use script or a similar method to mine...
 
Back