Solved

number of users on my site

Posted on 2004-05-03
6
199 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 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

Technology Partners: 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

Suggested Solutions

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 dynamically set the form action using jQuery.

738 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