*

rooman

  • ****
  • 231 posts
Number of connected users
« on: July 09, 2022, 02:24:06 PM »
Hello
What is the code that shows the number of users connected to a site
Currently
Thanks
« Last Edit: July 09, 2022, 02:54:13 PM by rooman »

*

MB Themes

Re: Number of connected users
« Reply #1 on: July 10, 2022, 08:42:09 AM »
Some stats could be there, but do not think online users counter exists.
https://docs.osclasspoint.com/husers-php
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

rooman

  • ****
  • 231 posts
Re: Number of connected users
« Reply #2 on: July 10, 2022, 09:24:03 AM »
Some stats could be there, but do not think online users counter exists.
https://docs.osclasspoint.com/husers-php

This site actually uses this view
mentioned codes https://docs.osclasspoint.com/husers-php
There is no current active users code :)
« Last Edit: July 10, 2022, 09:26:51 AM by rooman »

*

MB Themes

Re: Number of connected users
« Reply #3 on: July 11, 2022, 11:00:03 AM »
@rooman
In hUsers.php, update osc_total_users into following:
Code: [Select]
function osc_total_users($type = '', $condition = '') {
  switch($type) {
    case 'active':
      return User::newInstance()->countUsers('b_active = 1');
      break;
    case 'enabled':
      return User::newInstance()->countUsers('b_enabled = 1');
      break;
    case 'online':
      $limit_seconds = 300; // 5 minutes
      $threshold = date('Y-m-d H:i:s', strtotime(' -' . $limit_seconds . ' seconds', time()));
 
      return User::newInstance()->countUsers(sprintf('b_enabled = 1 AND b_active = 1 AND dt_access_date >= "%s"', $threshold));
      break;
    case 'custom':
      return User::newInstance()->countUsers($condition);
      break;
    default:
      return User::newInstance()->countUsers();
      break;
  }
}

You can then call osc_total_users('online') to get online users. Update will be included in Osclass 8.0.3
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

rooman

  • ****
  • 231 posts
Re: Number of connected users
« Reply #4 on: July 11, 2022, 12:59:52 PM »
@rooman
In hUsers.php, update osc_total_users into following:
Code: [Select]
function osc_total_users($type = '', $condition = '') {
  switch($type) {
    case 'active':
      return User::newInstance()->countUsers('b_active = 1');
      break;
    case 'enabled':
      return User::newInstance()->countUsers('b_enabled = 1');
      break;
    case 'online':
      $limit_seconds = 300; // 5 minutes
      $threshold = date('Y-m-d H:i:s', strtotime(' -' . $limit_seconds . ' seconds', time()));
 
      return User::newInstance()->countUsers(sprintf('b_enabled = 1 AND b_active = 1 AND dt_access_date >= "%s"', $threshold));
      break;
    case 'custom':
      return User::newInstance()->countUsers($condition);
      break;
    default:
      return User::newInstance()->countUsers();
      break;
  }
}

You can then call osc_total_users('online') to get online users. Update will be included in Osclass 8.0.3

Well done beautifully
Thank you very much :)

*

rooman

  • ****
  • 231 posts
Re: Number of connected users
« Reply #5 on: July 11, 2022, 01:06:12 PM »
But there is a problem that the number is increasing
Even if you leave the site
The number remains stable
for example
If the callers are 5 users
3 exited the site
5 people connected still appear

*

mwindey

  • *****
  • 484 posts
Re: Number of connected users
« Reply #6 on: July 11, 2022, 01:30:47 PM »
@rooman

it counts users online in last 5 minutes... if you wait 6 minutes the users will be 1 again normally (yourself).
$limit_seconds = 300; // 5 minutes

*

rooman

  • ****
  • 231 posts
Re: Number of connected users
« Reply #7 on: July 11, 2022, 01:36:10 PM »
@rooman

it counts users online in last 5 minutes... if you wait 6 minutes the users will be 1 again normally (yourself).
$limit_seconds = 300; // 5 minutes

Yes you're right
thank you all

*

rooman

  • ****
  • 231 posts
Re: Number of connected users
« Reply #8 on: May 01, 2024, 01:51:45 PM »
The previous code calculates the number of users currently on the site
Can the code be modified to include the number of browsers and not the number of users?

*

MB Themes

Re: Number of connected users
« Reply #9 on: May 01, 2024, 05:03:37 PM »
No.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots