How to count concurrent online visitors?

Posted on 2000-04-23
Last Modified: 2012-06-27
How to count concurrent online visitor during 15 minutes?
Question by:Hunte
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3

Expert Comment

ID: 2743545
Please specify question. That do you mean during 15  minutes

Accepted Solution

chkassen earned 100 total points
ID: 2743715
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:

MySQL - Dump

Hope this helps

LVL 12

Expert Comment

ID: 2743860
If you were to implement PHPlib ( 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. :)
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 2743877
why don't you just set a cookie with a 15 minute expiring time?
LVL 12

Expert Comment

ID: 2743890

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.

Expert Comment

ID: 2743948
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...
LVL 12

Expert Comment

ID: 2744059
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.

Expert Comment

ID: 2744153
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....
LVL 12

Expert Comment

ID: 2744319

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.

Expert Comment

ID: 2746787
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.

Expert Comment

ID: 2748407
Another solution is to have a look in your web server logfile (access_log for Apache).
- check the last 15 mins
- count all different IP.
And it's only script, no session or mysql
LVL 12

Expert Comment

ID: 2749434
"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,

Author Comment

ID: 2750025
I've got it.
Thanx a lot!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question