Count who else is on...
by The Architect
(461 views) -
(recorded 1/12/04 @ 2:10:24 AM)
I decided to add the "currently online" feature employed in VBulletin that shows you how many users and how many guests are "currently" browsing the site.
Took me awhile to work out the methodology for determining this statistic, here's the logic I finally chose:
Every time you view the page, it runs your through some pretty basic logic.
Are you logged in?
Every five minutes, when the daily entry/musing/notes today counts are compiled, we run the following little gem of code:
What's that do? Well, it formulates a timestamp based on the present time minus 17 minutes. Then, it runs a query that removes all entries in the "active users" table that are older than 17 minutes. Simple as that!
On the stats page, we do the following:
That just goes ahead and gives us the count for guests and logged in users, and generates that nice bit of text you see. choose_tenses() is a function I wrote that looks at the input (in the second case, $online_guests_count) and determines if the value is plural or not. If it is, it appends an 's' to the word, (in the same case, 'guest') if not, it leaves it as-is.
In case you're wondering, *that* function looks like this:
And that about wraps it up... Now you'll have a slightly better idea as to how many users are browsing with you. In theory, I could auto-refresh the value at the same interval I auto-refresh the ShoutBox, but that'd be more clicking and probably a bit annoying...
Questions? Comments? Praise? Do it all in the box below!
(By the way, this took about an hour and 15 minutes from concept to completion.)
Previous entry: Introducing: The ShoutBox! (Including Parts II & III)
Next entry: Introducing: The ShoutRoom (And Randomness!)
|Back to The Architect's journal :: Back to the journal index :: The Architect's latest entry|
|<-- Log in to leave a note, or create an account, if you don't already have one|