Solved

number of users on my site

Posted on 2004-05-03
6
201 Views
Last Modified: 2008-03-06
I need a php script that will count the number of people on my website at that particular moment in time.  I dont want the scripts to use a mysql database i want it to use flat text files.  

so for example......
all i need to do is add this to every webpage of mine
<?php include "livecounter.php"; ?>

and
<?php include "show_livecounter.php"; ?>

to display the number of people on my site
0
Comment
Question by:lord999
[X]
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
  • 2
6 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 205 total points
ID: 10977604
With PHP, there is a much simpler way to calculate the number of users online at the same time: simply count the number of session files.

<?

session_start();

/**
 * Calculate the number of users online by
 * counting the number of session files. Returns the
 * number of users on success, or -1 on failure.
 */
function getUsersOnline() {
    $count = 0;

    $handle = opendir(session_save_path());
    if ($handle == false) return -1;

    while (($file = readdir($handle)) != false) {
        if (ereg("^sess", $file)) $count++;
    }
    closedir($handle);

    return $count;
}

echo "users online = " . getUsersOnline() . "<br>";

?>
tUsersOnline() . "<br>";

?>

0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11019766
Have you succeeded !?
0

Featured Post

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!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

622 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