By taz3r on
Is there any way to display just the number of online users and unregistered users?
For example, a snippet that outputs something like this:
There are currently X registered users and X visitors online.
I'm not looking for it to display any avatars or names or anything, all I want is the number.
Comments
_
There's lots of good snippets in the snippet pages: http://drupal.org/node/66638
Thanks, but I've already
Thanks, but I've already seen/tried those.
Not what I was looking for.
_
well, they do what you asked for in your op-- there's no way to make alternative suggestions without more info. "not what i was looking for" doesn't tell us anything.
No they don't. The drupal 4
No they don't. The drupal 4 and 5 versions don't work for me. And the Drupal 6 version outputs a list of users that are online and the guest. I'm simply looking for a number for each.
If you enable the 'users'
If you enable the 'users' 'users stats' and 'tracker' module (I believe those are the three) you should see a block in your block menu name 'Who's Online'. I believe that is what you're looking for.
Yeah, but I'm only looking to
Yeah, but I'm only looking to display the number of users online. I don't need a list of their names/avatars.
Hello taz3r! I have exact the
Hello taz3r!
I have exact the same problem, i only want the number of online users und guests!
No names and pictures, only the two numbers!
Like in the headline of the standart Drupal Block "who is online".
I tested the following http://www.drupalcenter.de/node/24081#comment-85462 but it does not work for me in Drupal 6!
Has somebody an idea please?
greetz
Has someone an idea
Has someone an idea please?
The following Code counts the total registered users on my side, but how can i count the currently guests and online users?
Please help!
Thanks!
x of y registered and z guests
Drupal 6.x Example:
16 of 2,073 registered Users and 31 Guests online.
I use this on a regular basis in my theme_preprocess_page(&$variables) function
Template.php:
page.tpl.php:
an example of this can be found: http://www.sceneorlando.com/
All I've done here is: 1.) Query the database for the correct results (users online, total number of users, guests online) 2.) wrap the results in a few span tags so that i can "highlight" the statistics, 3.) Add results to a variable ($variables['users']) passing this variable to the page.tpl.php template and of course 4.) print this out in my page.tpl.php file
...remember to clear cache (/admin/settings/performance)
Yes, that´s it! Thanks a lot,
Yes, that´s it! Thanks a lot, it works!
But finally one last question, how can i get this query in an drupal block?
Add PHP to Block
A very simple way would be to create a block (/admin/build/block) enable your PHP filter (/admin/build/modules) and than just copy the code (not including the function { }) into said block. ...make sure that your input filter in your new block is set to php (as opposed to filtered html, etc).
Copy from this comment: //
Copy from this comment:
// set them amount of time that lapses for users to be "online"To this comment:
// x of y Users and z guests onlineTake that back... you have
Take that back... you have one more step.
This line of code:
<?php $variables['users'] = '<span class="highlight">' . $users_online . '</span> of <span class="highlight">' . $users_total . '</span> and <span class="highlight">' . $users_guests . '</span> guests'; // x of y Users and z guests online ?>needs to be fixed.It should look like:
<?php echo '<span class="highlight">' . $users_online . '</span> of <span class="highlight">' . $users_total . '</span> and <span class="highlight">' . $users_guests . '</span> guests'; // x of y Users and z guests online ?>All you are doing here is telling it print the variables (instead of passing it to page.tpl.php via $variables['users']
in case that was confusing
...Just in case that was confusing, here is what needs to be copied into your block.
Yes, thats it;) Thank you!
Yes, thats it;)
Thank you!
You don't need any interval of time.
You don't need any interval of time.
You don't want to show the number of users who have visited the site in the last 15 minutes (unless you intend to impress the visitors with a bigger, but false value).
You want to show the number of users who are online "at the moment".
The SESSIONS table tell us exactly what you want to know.
Modify your code to the following and you get what you exactly want.
Regards
One potential problem?
I'm not a programmer, coder, or developer, so I don't know how this problem could be resolved ... but one potential problem I see with this is that one user can generate more than one session. Which would probably explain why I have a great discrepancy between the results of this PHP block and a View I have set up to give me the usernames and IP addresses of online (registered) users.
The PHP block tells me that I have 62 registered users online. My View, however (which I have set up as Distinct, to list each user only once), lists just three registered users (myself included).
Any thoughts? Suggestions?
is there a Drupal 7 version
is there a Drupal 7 version of this?
I recently began using D7 and
I recently began using D7 and also missed the count of users that I had in D6's admin menu module. So I added it like so:
Note: I've designed this for use with the "Admin menu" module (https://www.drupal.org/project/admin_menu) v7.x-3.0-rc5 and Drupal v7.50.
This outputs the Admin Menu like so:
Content Structure Appearance People (71, 15) Modules Configuration Reports...showing that I have 71 guests and 15 users on my site.
Notes:
1) I've been playing around with different cache settings to authenticated users and despite now being logged in at work, my account from my home network last night is still listed in my sessions table. So I added a timer exclusion limit of 15 minutes. Therefore based on your site's caching the counts may or may not be a true instantaneous count of your visitors.
2) Indifferent to other code mentioned here I'm including myself (user 1) because I'm a logged in user too!
Make sure you clear your administration menu cache for this change to take effect!
Regards,
BigMike
Thanks so much for this! How
Thanks so much for this! How about if there is only one member online, how can I display the text "member," but if there is more than 1 member, such as 2, than display the text "members"?
For drupal 7
Is there a code for drupal 7.
It didn't worked with 7.41 core.
User stats module
I haven't tried it yet but this shows promise
https://www.drupal.org/project/user_stats
So it seems like you could make a view of users including anonymous users, put it in a block, make the block accessible to anonymous users.