Question

I'm running Drupal 7 web site with a Russian multiplayer card game and have to block some very annoying players every 4-5 days.

Before Drupal I was using phpBB 3. When these persons would come from a small city/village I'd just add their IP-network to the firewall rules, so that they can't re-register with a new mail address. This worked well in my case and my question is not about this policy.

My problem is that with Drupal, I can't find the last IP address used by a user id. I.e. the abuser is reported to me by other users and I know his uid, but I can't find his IP address in the logs, because:

  1. I've enabled syslog-logging and see the Drupal messages in /var/log/messagess but there is rarely a message about a user logging in, probably because sessions are long by default, and I'd like to keep it this way for user comfort.

  2. I've also enabled "database logging," but don't know where to see it (which database table).

Was it helpful?

Solution

If you have statistics module enabled, the "accesslog" table contains the IPs for all your visitors.

SELECT hostname FROM accesslog WHERE uid = %UID_FOR_YOUR_USER% LIMIT 1

If you do not have statistics enabled, I advise you to leave it off, even for this result, because enabling it, causes a severe performance-penalty.

In that case, you can use sessions table:

SELECT hostname FROM sessions WHERE uid = %UID_FOR_YOUR_USER% LIMIT 1

The benefit of the first over the latter, is that the first will always show you the latest hostname, whereas the latter might not always be up to date.

OTHER TIPS

As far as I know, Drupal doesn't reports the IP used by users in their user profile. You could create a custom module, verify the IP used by the user, and record it in your own database table; then you could show it in the user profile, to users who has the right permission (for example, to users with the permission to administer users).

The function you need is ip_address(), which you can use in your implementation of hook_user_login(). Implementing hook_user_view(), you can then show such information to the users with the right permission.

If you are using the database logging module, Drupal stores this information in the watchdog table, under the hostname column. You can either write custom queries to get at this information, or use the Views Watchdog module (currently only a dev release for 7.x, so I'm not sure how well it works in Drupal 7) to expose that table to Views.

Two recent modules may help with this:

User IP Log, which has Views integration, and IP Address Manager, which does not have Views integration but is intended to integrate with Manifest, Cave Your Trolls, and Misery-- all banning related modules.

session_id() gives you current user session-id whether he/she is a guest or a member.

$result = db_query("SELECT hostname FROM sessions WHERE sid = '".session_id()."'");
$data = db_fetch_object($result );
echo $data->hostname;
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top