WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Ruud on August 22, 2008, 04:30:19 PM

Title: New Snippet: Users Online
Post by: Ruud on August 22, 2008, 04:30:19 PM
In the series fun snippets, here is the Users Online snippet.

It displays a simple line that says "Currently: 21 users online".
Hovering over the line a tooltip popup will display a timestamp and the page that is being viewed.
When called with your "admin" IP address it will also display the IP address of the visitors and if it is called by a searchbot. (experimental bot detection).

See the snippet in action on http://www.wbhulp.nl (Dutch website) in the right top of the page.

Installation:

Install the zipfile as a normal module through the WB backend.
Add the php code to your template index.php.


Using the snippet:
Code: [Select]
<?php UsersOnline(); ?>    

Optional parameters: <?php UsersOnline$use_tooltip$prefix $suffix $single $admin_ip ?>

  $use_tooltip = Adds a small javascript to display a hovering tooltip with details of the current connections. (default := 1, 0 no tooltip)
  $prefix = The text in front of the user counter. ( default := "Currently: " )
  $suffix = The text after the user counter when there is more than one user online. (default = " users online")
  $single = The text after the user counter when there is just one user online. (default = " user online")
  $admin_ip = The IP address that will see more details. Details are IP address and browser name (if detected) (default := "127.0.0.1")

Customised Example: <?php UsersOnline("Online: " " users" " user""192.168.0.1" ) ; ?>

Have fun with it.

Ruud

[gelöscht durch Administrator]
Title: Re: New Snippet: Users Online
Post by: erpe0812 on August 22, 2008, 05:11:21 PM
Hi Ruud,

want to invite you to work with us on this project:

http://www.websitebakers.com

We are just a half step behind (or in front of) the start line....

rgds

erpe
Title: Re: New Snippet: Users Online
Post by: aldus on August 23, 2008, 06:06:52 PM
Hello Ruud

A nice one, and on a first look, clean as fresh fallen snow ;-)

But there are some unnessesary spaces instead of tabs,
seen in the attachment ... hard work for the preprocessor

Regards
Aldus

[gelöscht durch Administrator]
Title: Re: New Snippet: Users Online
Post by: pfreud01 on September 09, 2008, 04:09:36 PM
is it possible to display the name of registered users online in this snippet? i donĀ“t know to manage it.

best regards, pfreud01
Title: Re: New Snippet: Users Online
Post by: Ruud on September 09, 2008, 04:17:45 PM
No,

The data recorded by the snippet does not include that.
So it is not possible to display.

Maybe in a future version.

Ruud
Title: Re: New Snippet: Users Online
Post by: bupaje on September 18, 2008, 04:20:15 AM
Dumb question but is this registered users only, or total online users? Also if total users can it can be modified to show an image for every x amount of users with the numbers?

I was thinking it might be cool to create something like little characters, possibly with simple gif animations, hanging out in the stat box as a visual representation of how many users are online.
Title: Re: New Snippet: Users Online
Post by: Ruud on September 18, 2008, 09:28:02 AM
Dumb question but is this registered users only, or total online users?

It's total users. (and bots)

Also if total users can it can be modified to show an image for every x amount of users with the numbers?

I was thinking it might be cool to create something like little characters, possibly with simple gif animations, hanging out in the stat box as a visual representation of how many users are online.

It's open source. Be my guest. 8-)

Ruud
Title: Re: New Snippet: Users Online
Post by: bupaje on September 18, 2008, 04:01:14 PM
Thanks Ruud. :)
Title: Re: New Snippet: Users Online
Post by: bupaje on November 14, 2008, 07:40:15 PM
Has anyone had any problems with this? It has been working fine when suddenly today the page stops loading at this call

Code: [Select]
<?php UsersOnline("Currently: " " visitors viewing this page" " visitor viewing this page") ; ?>
Title: Re: New Snippet: Users Online
Post by: Ruud on November 14, 2008, 11:04:27 PM
Has anyone had any problems with this? It has been working fine when suddenly today the page stops loading at this call

Code: [Select]
<?php UsersOnline("Currently: " " visitors viewing this page" " visitor viewing this page") ; ?>

Is it still displaying anything?
Did you try to set the error reporting (advanced admin settings) to display all errors to see if it tells something?

I have it running on my site (http://WebsiteBaker.allwww.nl/) since day one without problems.

Ruud
Title: Re: New Snippet: Users Online
Post by: bupaje on November 14, 2008, 11:33:22 PM
Must be something Yahoo webhosting changed. I got a message today that they disabled some features because I got a new credit card number and forgot to tell them, so they couldn't charge me. Maybe that did it though everything else seems to work.

I tried to run it out of WB in a php page no luck. I also tried another script I found online that counts sessions as an alternative

http://www.devarticles.com/c/a/PHP/The-Quickest-Way-To-Count-Users-Online-With-PHP/1/

and no luck.

Hmm... just curious I use opendns.org - is it possible that somehow blocks access to my 'more info' ip that your snippet is looking for. In other words maybe only I cannot see it? I just added the code back, can you see the little gray box with user info at the bottom?

http://www.stormvisions.com/pages/home.php



Title: Re: New Snippet: Users Online
Post by: Ruud on November 14, 2008, 11:59:16 PM
Yes, there is a grey block at the bottom of the page.

The more info just compares ip addresses as strings. That cannot be an issue.
The other script is totally different, not using IP adresses, not using database. It's very strange both of the scripts don't work.

Database communication still works (you would not have pages if it didn't)
Can you still create or update normal pages?

Did Yahoo tell what features were disabled?

Ruud
Title: Re: New Snippet: Users Online
Post by: bupaje on November 15, 2008, 12:08:28 AM
No, they didn't say which ones. everything else seems normal. Very starnge.

I was able to implement this script found online

http://ronsguide.com/php/online/2/

and it outputs normally on my test page. It writes to a flatfile database if that sheds any light.
Title: Re: New Snippet: Users Online
Post by: vyni on November 15, 2008, 02:23:20 PM
Hi,

right now I had a look, and everything looks good to me.



[gelöscht durch Administrator]
Title: Re: New Snippet: Users Online
Post by: bupaje on November 15, 2008, 04:39:11 PM
That is a different script now - not very accurate either it seems. :)
Title: Re: New Snippet: Users Online
Post by: mracon on August 22, 2009, 12:18:58 PM
Where can I download the zip file, the download link takes me here.
Title: Re: New Snippet: Users Online
Post by: erpe0812 on August 22, 2009, 12:28:04 PM
Users Online (http://www.websitebakers.com/media/amasp_uploads/usersonline.zip)


rgds

erpe
Title: Re: New Snippet: Users Online
Post by: Hans>NULL on September 14, 2009, 08:53:53 PM
Hi
Get an error when setting  E_Strict
Code: [Select]
Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /www/modules/usersonline/include.php on line 38
Regards, Hans>NUL
Title: Re: New Snippet: Users Online
Post by: crnogorac081 on September 14, 2009, 10:12:48 PM
I got the same notification in PM module i built. I think it is just a note, not an error..

For example, If my hosting server is in US and I am in europe, I will set timezone to my local timezone in europe.. :) So its stupit to use same timezone from US , right ? I belive this is it...

If I am wrong someone please tell us what to do :))

cheers
Title: Re: New Snippet: Users Online
Post by: Hans>NULL on September 14, 2009, 11:27:13 PM
Ok, then a another message  :evil:
xhtml-Error:
Code: [Select]
   <p id="usersonline"><script language="JavaScript1.2" src="http://127.0.0.1:4001/wb28/modules/usersonline/overlib_mini.js" type="text/javascript"></script><span href="javascript:void(0);" onmouseover="return overlib('23:13:06 [127.0.0.1] /wb28/ (Home)  - Firefox<br/>',HAUTO,VAUTO,WIDTH,600,BGCOLOR,'#FFFFFF',FGCOLOR,'#FFFFFF',BORDER,5,WRAP);" onmouseout="return nd();">1 Besucher Online: </span> </p>
The "href" attribute is not valid for the "span" element.

Regards, Hans>NUL

Edit: Currently I am testing a few Snippets & Modules
Title: Re: New Snippet: Users Online
Post by: Vasiliy on December 03, 2009, 10:39:15 PM
Good evening!
I put this module on my website.
http://validator.w3.org/check found a lot of mistakes.
I have corrected all the errors.
You should find the file include.php and replace this code:

Quote
   if ($use_tooltip != 0) {
        while($res = $counter_res->fetchRow()) {
            if ($admin_ip == $ipaddress)
                $userlist .= date("H:i:s",$res['timestamp'])." [".$res['ip']."] ".$res['page']." (".$res['page_title'].") ".bot($res['user_agent'])."<br/>";
            else
                $userlist .= date("H:i:s",$res['timestamp'])." - ".$res['page']." (".$res['page_title'].")<br/>";
        }
        echo '<SCRIPT language="JavaScript1.2" src="'.WB_URL.'/modules/usersonline/overlib_mini.js" type="text/javascript"></SCRIPT>';
        echo "<span href=\"javascript:void(0);\" onmouseover=\"return overlib('$userlist',HAUTO,VAUTO,WIDTH,600,BGCOLOR,'#FFFFFF',FGCOLOR,'#FFFFFF',BORDER,5,WRAP);\" onmouseout=\"return nd();\">";
    }
    if($user == 1) {
        echo $prefix.$user.$single;
    } else {
        echo $prefix.$user.$suffix;
    }
    if ($use_tooltip != 0)
        echo "</span>";
   
and put the following code:

Quote
   if ($use_tooltip != 0) {
        while($res = $counter_res->fetchRow()) {
            if ($admin_ip == $ipaddress)
                $userlist .= date("H:i:s",$res['timestamp'])." [".$res['ip']."] ".$res['page']." (".$res['page_title'].") ".bot($res['user_agent'])."&lt;br />";
            else
                $userlist .= date("H:i:s",$res['timestamp'])." - ".$res['page']." (".$res['page_title'].") &lt;br />";
        }
        echo '<script language="JavaScript1.2" src="'.WB_URL.'/modules/usersonline/overlib_mini.js" type="text/javascript"></script>';
        echo "<a href=\"javascript:void(0);\" onmouseover=\"return overlib('$userlist',HAUTO,VAUTO,WIDTH,600,BGCOLOR,'#FFFFFF',FGCOLOR,'#FFFFFF',BORDER,5,WRAP);\" onmouseout=\"return nd();\">";
    }
    if($user == 1) {
        echo $prefix.$user.$single;
    } else {
        echo $prefix.$user.$suffix;
    }
    if ($use_tooltip != 0)
        echo "</a>";    
Title: Re: New Snippet: Users Online
Post by: Stefek on December 07, 2009, 06:32:53 PM
Hello Ruud,

I am going to use this nice snippet on a project.

It's very nice but I would like to show something like:
currently 35 users online | 15 logged in and 20 visitors.

Could this be implemented somehow?

Maybe you can give me some hints, so I can learn and do the rest myself (with some help).

Kind regards,
Stefek

Title: Re: New Snippet: Users Online
Post by: Ruud on December 07, 2009, 10:40:51 PM
To do that it will need an extra field in the counter table.
A simple check on the session variable could be done to see if the current user is logged in.
A bit more logic will be needed to query the table to produce the correct counters.
Some extra parameters will be needed to be accepted to display more text fragments.

If I find some time the next few days, I will have a look to see if I can add this feature.
I think this is not te best project to start learning PHP coding.

R
Title: Re: New Snippet: Users Online
Post by: Stefek on December 08, 2009, 01:02:33 AM
Hello Ruud,
thanks for your hints, and yes, reading your explanations I agree with ...

I think this is not te best project to start learning PHP coding.

And if you find some time it would be a very nice extension for this snippet.

Kind regards,
Stefek

Title: Re: New Snippet: Users Online
Post by: WDStudio on March 02, 2010, 09:15:51 PM
How can I set timezone (GMT +1) for this module?
Title: Re: New Snippet: Users Online
Post by: Ruud on March 02, 2010, 11:24:22 PM
The snippet uses the php->date() function to display the timestamp.
The timezone used is whatever is setup in the php configuration, or the webserver itself.

A function like this (http://php.net/manual/en/function.date-default-timezone-set.php) could be added to the snippet to change the output to a different timezone.
Title: Re: New Snippet: Users Online
Post by: WDStudio on March 06, 2010, 08:31:01 PM
Great joob.

Thanks Ruud  :-)
Title: Re: New Snippet: Users Online
Post by: Bramus on January 01, 2011, 07:55:00 PM
Is it possible to modify the counter so it can also show the total visitors?

Like adding a field that contains the total visitors and each time a new visitor is on the website (home page) it does +1 ?
Title: Re: New Snippet: Users Online
Post by: Ruud on January 01, 2011, 10:58:02 PM
Isn't that the same a the simple pagecounter (http://www.websitebakers.com/pages/code-snippets/counters/small-counter.php)?
In that script the counter per page is updated once per session.
Title: Re: New Snippet: Users Online
Post by: Bramus on January 02, 2011, 02:43:52 AM
Hmm looks like a usefull script for only the home page as that is what we want to count. I'm gonna look into it and see if we can use it for a new website!

Thanks :)
Title: Re: New Snippet: Users Online
Post by: Argos on January 07, 2011, 08:01:45 PM
Would be nice if this could be a user friendly droplet [[UsersOnline]]  :-D
Title: Re: New Snippet: Users Online
Post by: Ruud on January 07, 2011, 11:36:55 PM
since this is typically a function to be used on all pages in your website, I do not see the big difference in adding
<?php UsersOnline(); ?>
instead of
[[UsersOnline]]

On the other hand, you can always create a droplet that captures the output of the snippet..
Code: (Droplet:UsersOnline (remember to install the snippet first) ) [Select]
<?php
ob_start
();
UsersOnline();
$users ob_get_contents();
ob_end_clean();
return 
$users;
?>
Note: the dropletcode above is not tested!

Title: Re: New Snippet: Users Online
Post by: Argos on January 07, 2011, 11:51:22 PM
Thanks for your answer Ruud. Personally I think just the other way round: this is typically a function for single use on a site, and I suggested a droplet because it's more easy for both me and clients :-) 
But adding a droplet based on first installing a snippet sounds a bit like double work... It's not that important (for me) anyway.
Title: Re: New Snippet: Users Online
Post by: Schwarzlicht on January 22, 2012, 02:47:04 PM
hello, I would like each group to display the user behind the name. How can I do that?