Users Online

boboo

Avatar: boboo

2011-02-18 21:41

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.

» Quick.Cart v3.x

http://it-service.kimla.de

kuzco

Avatar: kuzco

2011-02-21 22:41

Although my polish knowledge is very very small, it was simple to implement.

Thanks for this plugins. Nice work.

kuzco

Avatar: kuzco

2011-02-28 22:13

boboo,
have one wish to your script.

It is possible to add an additional file with all connected IP all-over the time, means a file without deleting the IP from UsersOnline.bob ?

thx

boboo

Avatar: boboo

2011-02-28 23:14

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?

http://it-service.kimla.de

kuzco

Avatar: kuzco

2011-03-01 08:57

yes, every connection please and yes too for the time.

thx

cachousam

Avatar: cachousam

2011-03-01 09:54

Hi
good idea with this plugin.
But for me ,i have a bug.
In my main page off admin i have this error:*

Fatal error: Call to undefined function: file_put_contents() in /web/mysite/www/core/common.php

I have made a mistake?

cachousam

Avatar: cachousam

2011-03-01 09:56

The same error in main page for customer

kuzco

Avatar: kuzco

2011-03-01 13:58

bobo,
is there any difference to the plugin on http://opensolution.org/download,en,,18.html?sFile=Quick.Cart/plugins/usersOnline_v0.1.zip ?

thx

kuzco

Avatar: kuzco

2011-03-01 14:03

Have tried also:
http://opensolution.org/download,en,,18.html?sFile=Quick.Cart/plugins/usersOnline_v0.1.zip

This will add more than 1 entry per IP per access:
1298984467$127.0.0.1$
1298984475$127.0.0.1$

This was not done with the above script.

cachousam

Avatar: cachousam

2011-03-01 14:52

Kuzco
For my problem
Do you have a answer please?
Have you write the script above without change?

kuzco

Avatar: kuzco

2011-03-01 14:56

yes, i have used the above script without any changes.

have you tried to create the file manual and set the permissions to 777 ?

cachousam

Avatar: cachousam

2011-03-01 15:37

the file to create it is really: UsersOnline.bob.php?
And it must be no empty?

boboo

Avatar: boboo

2011-03-01 15:58

@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"?

http://it-service.kimla.de QC- & QCMS-plugins

kuzco

Avatar: kuzco

2011-03-01 17:06

@boboo:
I have not created any file.
The script hasl created the file for me and after taht I have two entries.

boboo

Avatar: boboo

2011-03-01 21:40

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".

http://it-service.kimla.de QC- & QCMS-plugins

kuzco

Avatar: kuzco

2011-03-01 22:22

boboo,
yes you are right.
due to the fact that the script was the same (english instead of polish) i have only changed the script - not more.

sorry for the confusion.

thx
kuzco

kuzco

Avatar: kuzco

2011-03-02 12:18

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.

Please try it first a demo environment !!

boboo

Avatar: boboo

2011-03-02 12:55

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 :-)

http://it-service.kimla.de QC- & QCMS-plugins

kuzco

Avatar: kuzco

2011-03-02 15:05

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.

Back to top
about us | contact