Solved

number of users on my site

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

785 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