SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Nov 8, 2009, 11:35 #1
How a counter of users ? such as ---> (231 Viewing)
I want to count how many users are actually viewing the page, How is that possible?
Thank you guys!
-
Nov 8, 2009, 11:48 #2
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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 likePHP 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";
-
Nov 8, 2009, 12:12 #3
Now There is a parse error some where in the line below.
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?
-
Nov 8, 2009, 12:22 #4
- Join Date
- Oct 2009
- Posts
- 1,852
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Nov 8, 2009, 12:41 #5
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 />'; ?>
-
Nov 8, 2009, 12:55 #6
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..
Bookmarks