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: Show IPs And Domains Of Current Visitors

Submitted by on April 3, 2012 – 8:14 amNo Comment

If you need to get information about users who are currently on a site, you can do this in two ways:

  • Enable “Who’s online” standard block

  • Create a custom block with the list of online users (their IPs and domain names)

Below, I will tell you how to create a custom block.

Create a custom block

The code below will show IP-addresses and domains of a site guests. The block appearance is similar to this one:
Так выглядит работающий блок

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 adjust this snippet to Drupal 6, you will need to replace db_num_rows() function with
mysql_num_rows() according to API  of mysql_num_rows() function.

Note: don’t forget to setup permissions to a block with this info. Users want to be anonymous – they may be disappointed if they see their personal info in a free access. Custom “Who’s Online” block

Good luck!

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.