I want to count how many users are actually viewing the page, How is that possible?
Thank you guys!
Printable View
I want to count how many users are actually viewing the page, How is that possible?
Thank you guys!
It displays how many users requiestd this page in past few minutes.
Simpliest way to do it is write down IP address and time of request.
something likeit is just raw example. not a real code. locks must be taken inaccount.PHP Code:$data=file_get_contents("counter.dat");
$counter=unserialize($data);
$counter[$_SERVER['REMOTE_ADDR']]=time();
foreach ($counter as $key = > $value) if ($value < (time()-180)) unset $counter($k);
$data=serialize($counter);
file_put_contents("counter.dat", $data);
echo count($counter)." viewing";
Now There is a parse error some where in the line below.
Code where the parse error isQuote:
Parse error: parse error, expecting `')'' in
Code:$data=file_get_contents("counter.dat");$counter=unserialize($data);$counter[$_SERVER['REMOTE_ADDR']]=time();foreach ($counter as $key = >
Do I have to download the counter.dat file before using the code?
Yes my bad. There is mistake.
But if you don't know PHP syntax, this code isn't for you. It is just example, shows the way. Not a real code to put into site.
I have found this script php counter, but it is displaying a parse error on line 77 see the commented 77 line. My limited eyes doesn't notice any parse error can you see any?
Thank you..
PHP Code:<?php
session_start();
/* Define how long the maximum amount of time the session can be inactive. */
define("MAX_IDLE_TIME", 3);
function getOnlineUsers(){
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 { // line 77 where the parse error is
return false;
}
}
echo 'Number of online users: ' . getOnlineUsers() . '<br />'; ?>
Thank to Alex help me find the parse error.
i counted the brakets twice and i thought there were perfect but yes i missed the first if statment.
Thank you..
PS: Two eyes can see better than one..