• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 784
  • Last Modified:

How to count concurrent online visitors?

How to count concurrent online visitor during 15 minutes?
0
Hunte
Asked:
Hunte
  • 5
  • 3
  • 2
  • +3
1 Solution
 
crow_nvCommented:
Please specify question. That do you mean during 15  minutes
0
 
chkassenCommented:
It's quite simple to do that. I have seen it on several pages. It works as follows:

When a user visits the webpage you add his ip and the current time to a database.
And then you also delete all the entries out of the database which have a value in their time field higher than current time + 15 Minutes.
Then you simply count the entries in the database with
$result = mysql_query( "SELECT Count(*) as total FROM userlog");
and print the result out to a webpage.

That's it.

You can get the full source code over at the following URL:

PHP - Source:
http://www.php-homepage.de/source/source.html?page=UserLog.php3

MySQL - Dump
http://www.php-homepage.de/source/source.html?page=UserLog.sql

Hope this helps

--
chkassen
0
 
j2Commented:
If you were to implement PHPlib (http://phplib.netuse.de) a session handling routine is included. It works on the principle that chkassen suggests, but it comes in a nice package, and does so much more. :)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
alexdgCommented:
why don't you just set a cookie with a 15 minute expiring time?
0
 
j2Commented:
Uhm..

1. Then he would have to query all cookies to get the info, and that can only be done when a client requests a page.

2. I dont accept cookies on my systems part from well known e-commercs sites etc etc so that would probably skew the accuracy of the measurements.
0
 
alexdgCommented:
if one does not accept cookies, than "session" solution won't work as well for that person... besides, what happens if IP changes during 15 minutes log time?? cookie is the most accurate solution... imho...
0
 
j2Commented:
with the phplib session handling, it wont matter if the ip changes of either the server or the client. Read the soruces, it is quite clever.

With phplib, if a client does not accept a cookie, it automatically fall back to "get mode" in which it appends the session info to every url used within the site, thereby still keeping the session data consistent.
0
 
alexdgCommented:
eh... where can i get that wonderful "phplib" which somehow appends session id to the end of all my anchors on the page?? i'd like to take a look at the code which makes it work this way....
0
 
j2Commented:
http://phplib.netuse.de

be sure to read the docs, but basically you use the page_open() and page_close() functions, and then write all urls in the form of

<a href = "<?php $sess->purl("http://somehost/somapage.php3") ?>">Description</a>

And it will automatically append session info to the anchors in get mode if the user refuses cookies.
0
 
chkassenCommented:
Well phplib is cool for sessions and all this stuff but you really do not need sessions in this simple case.

Because you want to display the information about concurrent visitors to all visitors you can not store this value in a session. Because then the data would be available only to one user.
0
 
us111Commented:
Another solution is to have a look in your web server logfile (access_log for Apache).
examples:
- check the last 15 mins
- count all different IP.
And it's only script, no session or mysql
0
 
j2Commented:
"Because you want to display the information about concurrent visitors to all visitors you can not store this value in a session. Because then the data would be available only to one user." - Yes, but since _all_ users/sessions can access the SID and date from the DB, you can get the hits from there, thats how i do it.

us111: that works if you have access to the logs, but will be slow and resource consuming,
0
 
HunteAuthor Commented:
I've got it.
Thanx a lot!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now