Count number of users online?

apoorav

New Member
Messages
110
Reaction score
2
Points
0
How to count number of online users? plz give me the code to display number of online users and total users.

THANKS in advance!!:biggrin:
 

apoorav

New Member
Messages
110
Reaction score
2
Points
0
Code is good but there are some configuration problems with database plz solve them
 

miguelkp

Member
Messages
304
Reaction score
7
Points
18
I use a prefab counter: Histats.com has a lot. You can choose a counter (they have a lot, diferent counters... I'm sure at least one will look fine with your website template). And then customize what info is going to be displayed.
 

apoorav

New Member
Messages
110
Reaction score
2
Points
0
I use a prefab counter: Histats.com has a lot. You can choose a counter (they have a lot, diferent counters... I'm sure at least one will look fine with your website template). And then customize what info is going to be displayed.

Thanks,but i want php code with full installation instructions:biggrin:
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
This could be very simple..

Each login creates a session (if you are using sessions i.e. you have session_start() at the top of the page)

You could then just count the amount of active sessions.

PHP:
/* Define how long the maximum amount of time the session can be inactive. */ 
define("MAX_IDLE_TIME", 3); 

function countactiveusers(){ 

if ( $directory_handle = opendir( session_save_path() ) ) { 
$count = 0; 
while ( false !== ( $file = readdir( $directory_handle ) ) ) { 
if($file != '.' && $file != '..'){ 
// Comment the 'if(...){' and '}' lines if you get a significant amount of traffic 
if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) { 
$count++; 
} 
} 
closedir($directory_handle); 

return $count; 

} else { 
return false; 
} 

} 

echo 'Number of users online: ' . countactiveusers() . '<br />';

Simples!

This method does not rely on using a database which is faster, but gets you no stats :(
 

apoorav

New Member
Messages
110
Reaction score
2
Points
0
This could be very simple..

Each login creates a session (if you are using sessions i.e. you have session_start() at the top of the page)

You could then just count the amount of active sessions.

PHP:
/* Define how long the maximum amount of time the session can be inactive. */ 
define("MAX_IDLE_TIME", 3); 

function countactiveusers(){ 

if ( $directory_handle = opendir( session_save_path() ) ) { 
$count = 0; 
while ( false !== ( $file = readdir( $directory_handle ) ) ) { 
if($file != '.' && $file != '..'){ 
// Comment the 'if(...){' and '}' lines if you get a significant amount of traffic 
if(time()- fileatime(session_save_path() . '\\' . $file) < MAX_IDLE_TIME * 60) { 
$count++; 
} 
} 
closedir($directory_handle); 

return $count; 

} else { 
return false; 
} 

} 

echo 'Number of users online: ' . countactiveusers() . '<br />';

Simples!

This method does not rely on using a database which is faster, but gets you no stats :(

I want the script to count number of users online and of different country flags counter with full installation instructions with details according to X10hosting databse
 

ChatIndia

Community Advocate
Community Support
Messages
1,408
Reaction score
30
Points
48
why you want to use your own database. I've seen many website which gives you the same service and that too without the need of any database in your site.
 

connerty

New Member
Messages
2
Reaction score
0
Points
0
Well really you need to create your own depending on your own circumstances. For instance where would you retrieve where the live? Via a database of your members or via the IP pool from wich they come from. All of these different solutions will work only for your circumstances. Also it is nice to be asked if it is okay for us to help you with a problem as apposed to be being told to fix it for you.
 
Top