1. Utwórz w db/ pusty plik UsersOnline.bob 2. W core/common.php dodaj funkcje: function usersOnline(){ $sPlik='db/UsersOnline.bob'; $time=time(); $iOnline=$time-600; $ip=$_SERVER['REMOTE_ADDR']; $aCheckTime=@file($sPlik); while(list($line_num,$line)=@each($aCheckTime)){ $sCzas=explode('$',$line); if($sCzas[0]<=$iOnline){ $contents=file_get_contents($sPlik); $sPusty=null; $sZamien=str_replace($line,$sPusty,$contents); file_put_contents($sPlik,$sZamien,LOCK_EX); chmod($sPlik,0777); } } $aCheckIP=@file($sPlik); while(list($line_num,$line)=@each($aCheckIP)){ $aIP=explode('$',$line); if($aIP[1]==$ip){ $contents=file_get_contents($sPlik); $sPusty=null; $sZamien=str_replace($line,$sPusty,$contents); file_put_contents($sPlik,$sZamien,LOCK_EX); chmod($sPlik,0777); } } file_put_contents($sPlik,$time.'$'.$ip.'$'."\n", FILE_APPEND | LOCK_EX); $Zawartosc=file($sPlik); $iUserOnline=count($Zawartosc); return $iUserOnline; } function usersOnlineAdmin(){ $sPlik='db/UsersOnline.bob'; $sZawartosc=file($sPlik); $iUserOnline=count($sZawartosc); return $iUserOnline; } 3. W index.php NAD if(isset($aActions['f']... dodaj: $iUsersOnline=usersOnline(); 4. W admin.php NAD loginActions($p,.... dodaj: $iUsersOnlineAdmin=usersOnlineAdmin(); 5. W templates/container.tpl dodaj w odpowiednie dla wyglądu strony miejsce zmienną $iUsersOnline 6. Jeśli chcesz to oglądać też w panelu admina, wstaw w jakąś templatkę w templates/admin/xxx.tpl zmienną $iUsersOnlineAdmin
Punkt 1. nie jest konieczny, lecz jeśli nikt jeszcze nie wejdzie na stronę i tego pliku nie będzie, w panelu admina pojawi się meldunek o braku tego pliku. Liczba 600 w górnym przykładzie jest ilością sekund, przez jaką uznajemy jakiegoś usera, że jest online od momentu "dotknięcia" przez niego naszej strony.
Zasada działania: Plik UsersOnline.bob (jeśli nie jest pusty) ma strukturę: Czas$IP$ Bierzemy Czas i IP użytkownika. Przeszukujemy plik UsersOnline.bob po kryterium Czas - 600 sekund (czyli szukamy wpisów starszych niż 10 minut). Jeśli taki znajdujemy - kasacja tej linijki. To samo z IP, jeśli taki istnieje - kasacja tej linijki. Po czym wpisujemy świeży Czas i IP. To się dzieje tylko z poziomu strony gościa. Z panelu admina tylko odczytujemy ilość linijek (a co za tym idzie, userów online) z Pliku. Co oznacza, że login na stronie admina nie zwiększa liczby userów online.
Zabawę we wkładanie tych zmiennych w templatkach i ich "designowanie" zostawiam wam.
Should be the IPs kept double? E.g. today came someone with X.Y.Z.V ip-address, and a week after again. Should this be written every time, or only once? If everytime, do you need the time of this fact?
@cachousam, Your php on server is to old. You need at least php5.
@kuzco, 2 entries from one IP: do you have in /db/usersonline.php the first line with: <?php exit;?> Or you just created an empty file "usersonline.php"?
kuzco, You gave the link to the zip file with installation instruction and a template usersonline.php file. In the FIRST paragraph of the "howTo" there is a line: step 1) copy "usersonline.php " to directory "db/" of Your Quick.Cart installation. set "usersonline.php" fileattribute to 777. !!! If you don't follow the instructions, so don't be surprised when the "machine fails".
Sometimes when checking how many users are online, i see that from 7 online-users 5 users are crawlers and/or bots from google or yahoo. This fact will forged the whole statistic. Therefore I have edited the usersOnline_v0.1 script in a way that all crawl/bots connections from google and /or are not added to the useronline parameter. All crawl/bots connections from google and /or yahoo are saved in usersonlinebots.php.
Heres is the way: 1. Copy a fresh usersonline.php to usersonlinebots.php and copy/move it to \db. 2. In core\common.php put under: $sFile='db/usersonline.php'; this line: $sFileBots='db/usersonlinebots.php'; /* Bots online */ 3. Replace in core\common.php @file_put_contents($sFile,$iTime.'$'.$sIP.'$'."\n",FILE_APPEND|LOCK_EX); with $host = gethostbyaddr($sIP); if ( (strstr($host,'googlebot.com')) || (strstr($host,'crawl.yahoo.net')) ) { @file_put_contents($sFileBots,$iTime.'$'.$sIP.'$'.date('Y-m-d_H-i').'$'.$host.'$'." \n",FILE_APPEND|LOCK_EX); } else { @file_put_contents($sFile,$iTime.'$'.$sIP.'$'.date('Y-m-d_H-i').'$'.$host.'$'."\n&q uot;,FILE_APPEND|LOCK_EX); }
I have added the following attributes: hostname of user, user agent and referrer.
Please keep in mind that no entry in usersonlinebots.php will be deleted - I have no idea how to implement this. Therefore sometime it is necessary to delete db/usersonlinebots.php. This means that this file can grow very fast. To make sure that this will not happen, please only delete "@file_put_contents($sFileBots,$iTime.'$'.$sIP.'$'.date('Y-m-d_H-i').'$'.$host.'$'. "\n",FILE_APPEND|LOCK_EX);" in the script above.
Perhaps someone can impleent this in the same way how db/usersonline.php verify the connections.
I have the same issue withe the plugin simpleCounter_v0.1 and will try to edit this script also, so that this statistic will not be forged in the same way. On my homepage I think that from 600 users per day moree than 500 are from crawlers/bots.
Why keep the bots entries? Why write them to ...bots.php? It is enough to getHost and then ask: If not "googlebot" in Host then write to normal usersonline database. It means: if the "google" is in Host the entrie will not be written anywhere.
Delete the: $sFileBots='db/usersonlinebots.php'; /* Bots online */ Don't change the old lines with file_put_contents, the line with $host= getHostByAddr is OK, and change the line: if ( (strstr($host,'googlebot.com')) || (strstr($host,'crawl.yahoo.net')) ) { to: if ( (!strstr($host,'googlebot.com')) || (!strstr($host,'crawl.yahoo.net')) ) {
Of course you can add the "|| (!strstr($host,'another_bots_you_know))" in the if-statement, and they will disappear in nirvana :-)
Yes, this is working too. But is has to be an AND operator not an OR operator if ( (!strstr($host,'googlebot.com')) && (!strstr($host,'crawl.yahoo.net')) ) {
Can we come back to the issue to log all connected user all over the time ? I have checked the simpleCounter script. Does $aVisits[0]++; $aVisits[1]++; increase the counter for today/total ? If yes, it will be easy to "delete" also all bots connections for the counter.