PDA

View Full Version : Logging IP Addresses - is there a mod for this?


bryanb
02-15-2011, 05:20 AM
I have a member who thinks his account has been accessed by someone else. He's been a member for several years and has never posted so only one IP address shows in his account profile. I'm assuming that vB only logs IPs when a user posts (please correct me if I'm wrong).

Is there a mod, or any way to view IPs that have accessed an account over a certain period of time? Any assistance would be truly appreciated. Thanks!

Using 3.8.6 btw :)

kh99
02-15-2011, 09:53 PM
I was going to use this for something I was working on: create a plugin with hook location global_complete and this code:


if ($vbulletin->userinfo['userid'] AND $vbulletin->session->created)
{
$fp = @fopen('memberips.log', 'a'); // <--- add path to writable directory
if (!empty($fp))
{
fwrite($fp, IPADDRESS . ',' . $vbulletin->userinfo['userid'] . ',' . $vbulletin->db->escape_string($vbulletin->userinfo['username']) . "\n");
fclose($fp);
}
}


Note that you probably have to add a path to the front of the file name in fopen() to put the log file in a writable directory.

In any case, this logs the user name, id, and ip whenever a session is created. You would probably want to add the data/time to this.

Note: I think this will be OK but I didn't try it on a busy site. I also don't know if the info might somehow already be available from the web server logs.

ETA: of course you could also add a check for the userid if you only want to log that one user.

Andy
02-16-2011, 05:22 AM
Thank you kh99. That is a very useful code.

sub_ubi
11-15-2012, 04:39 PM
Thank you very much for this code.

--------------- Added 1353004307 at 1353004307 ---------------

Same thing with timestamps added,

if ($vbulletin->userinfo['userid'] AND $vbulletin->session->created)
{
$fp = @fopen('memberips.log', 'a'); // <--- add path to writable directory
if (!empty($fp))
{
fwrite($fp, vbdate($vbulletin->options['dateformat'] . ',' . $vbulletin->options['timeformat']) . ',' . $vbulletin->userinfo['userid'] . ',' . $vbulletin->db->escape_string($vbulletin->userinfo['username']) . ',' . IPADDRESS . "\n");
}
}

RedTurtle
11-19-2012, 08:09 AM
Very useful, thanks guys! Any obvious changes needed for it to work on vB4?

ozzy47
10-19-2013, 04:22 PM
One thing I noticed with this, is that it only adds it to one line, there is no carriage return after each entry.

--------------- Added 1382216131 at 1382216131 ---------------

Got it, needed to add \r