Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: List of IP & Domains of Users Who Are Currently Online

Submitted by on June 1, 2010 – 8:18 amNo Comment

Problem

Get information about users who are currently on the site


Solutions

  • Enable the standard block "Who’s online"
  • Create your own block with the necessary information

 

Create block

This code shows IP addresses and domains of anonymous users (guests).

Example:
clip_image002

Drupal 5:

<?php
$number = db_result(db_query(‘SELECT COUNT(uid) AS number FROM {users} WHERE status=1′));
        if (user_access(‘access content’)) {
          // Count users with activity in the past defined period.
          $time_period = variable_get(‘user_block_seconds_online’, 900);
          // Perform database queries to gather online user lists.
          $guests = db_fetch_object(db_query(‘SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0′, time() – $time_period));
          $guests_hostname = db_query(‘SELECT hostname FROM {sessions} WHERE timestamp >= %d AND uid = 0′, time() – $time_period);
          $total_guests = db_num_rows($guests_hostname);
          $users = db_query(‘SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC’, time() – $time_period);
          $total_users = db_num_rows($users);
          // Display a list of currently online users.
          $max_users = variable_get(‘user_block_max_list_count’, 10);
          if ($total_users && $max_users) {
            $items = array();
            while ($max_users– && $account = db_fetch_object($users)) {
              $items[] = $account;
            }
            $output.="<h7>Users</h7>";
            $output .= theme(‘user_list’, $items, NULL);
          }
          // Display a list of currently online guests.
          if ($total_guests) {
            $output.="<div class=\"item-list\"><h7>Guests</h7><ul><fine>";
            $guestitems = array();
            while ($guests– && $account = db_fetch_object($guests_hostname)) {
              $guestitems[] = $account->hostname;
              $output.="<li><a title=\"Go to address\" href=\"http://$account->hostname\">$account->hostname</a>
              <a title=\"Go to address\" href=\"http://".gethostbyaddr($account->hostname)."\">".gethostbyaddr($account->hostname)."</a>       ";  
            }
           $output.="</fine></ul></div>";
          }
        }
        return $output;
?>

Drupal 6:

To adopt this snippet for D6, you should replace db_num_rows() function to mysql_num_rows() in accordance with mysql_num_rows() API function.

Attention:
Do not forget to adjust access rights to the block with this info. Users want be anonymous and showing their info can upset them…

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.