Get a fully registered user in Drupal

I have this Drupal site and I want to have my own chat (I can’t use the chat module because I need to personalize it). I have to get all online users, but I do not see any variable for this.

I can only get the name of the current user, but not all registered users.

+3
source share
1 answer

You can get a list of all registered users by requesting a session table. I assume you are using Drupal 6.

<?php
$result = db_query('SELECT uid FROM {sessions} WHERE uid != 0');
$users = array();
while($user = db_fetch_array($result)) {
  $users[] = user_load($user);
}

The request excludes sessions for uid = 0, because these are anonymous users. $usersis an array of user objects, as described in the Drupal Docs API .

, , (, ), user_load() while , user_load() . :

<?php
$result = db_query('SELECT u.uid, u.name FROM {sessions} s INNER JOIN {users} u ON u.uid = s.uid WHERE s.uid != 0');
$users = array();
while($users[] = db_fetch_array($result));

- ( ), , (.. , ):

$timestamp = time - 3600; // 3600s is one hour.
$result = db_query('SELECT uid FROM {sessions} WHERE uid != 0 AND timestamp >= %d', $timestamp);

. , , - - 10 , :

$limit = 10; // Limit to the last 10 users.
$result = db_query_range('SELECT uid FROM {sessions} WHERE uid != 0 ORDER BY timestamp DESC', $timestamp, 0, $limit);

, (, $limit 3600s), _set(), variable_get() variable_del().

+12

Source: https://habr.com/ru/post/1751160/


All Articles