Solved

number of users on my site

Posted on 2004-05-03
6
190 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
  • 2
6 Comments
 
LVL 1

Expert Comment

by:Daniel_Hegener
Comment Utility
0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 205 total points
Comment Utility
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
Comment Utility
Have you succeeded !?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now