Welcome Guest, Not a member yet? Register   Sign In
How to count the current number of users visiting the website?
#1

[eluser]Sinclair[/eluser]
Hi,

I need to count the current number of users visiting the website.

There are some easy way of doing this with codeigniter?

Best Regards,
#2

[eluser]n0xie[/eluser]
You could do a count on the session table if you use DB Sessions. It's not 100% accurate but it gives an indication...
#3

[eluser]Sinclair[/eluser]
I have many views/controllers that are not calling Session Class, there are othe possibilities?

Best Regards,
#4

[eluser]The Casual Bot[/eluser]
you really would need sessions for this to work just autoload it
#5

[eluser]mddd[/eluser]
I would say there is no other way then to somehow store something in the database each time you encounter a visitor. And then count the number and display it.
If you are already storing something (because of sessions) that is the logical way to go. You can use the "last updated" value of a session to make the relevant selection.

If you don't use the sessions, you could store something else, like the ip of the visitor, along with the time of visit. If you delete those entries when you don't want to count them anymore, you have a count of the number.

Of course, if you use ip's, multiple visitors from a single ip will count as one -- you could also use some kind of hash of the ip, browser agent, and other factors, trying to uniquely count the users.

I suggest you use the sessions class, even only for this purpose.. it's no use adding another layer of complexity if not neccessary.
#6

[eluser]WanWizard[/eluser]
[quote author="n0xie" date="1277845397"]You could do a count on the session table if you use DB Sessions. It's not 100% accurate but it gives an indication...[/quote]
For that reason I added a 'last_update' field to the session table, which is updated at every page request. The last_activity field has nothing to do with what the name implies, it only gets updated when the session key is updated.

This also allows me to run queries like "who is currently logged on?".




Theme © iAndrew 2016 - Forum software by © MyBB