Solved

number of users on my site

Posted on 2004-05-03
6
192 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
ID: 10977235
0
 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

919 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

20 Experts available now in Live!

Get 1:1 Help Now