Help - Search - Members - Calendar
Full Version: I Want To Log Members And Ip's
Invision Power Services > Community Forums > Community Web Design and Coding
~Jacey~
I want to be able to log members and their IPs and time they visited, using online.php I wrote this code I'm unsure if it will work or where I should put it in the file. Any help would be greatly appreciated. We are having problems on my forum. I was thinking the very bottom of online.php or should it go above Process Row? I don't have a test board sad.gif

CODE
/*-------------------------------------------------------------------------*/
// Write to document
/*-------------------------------------------------------------------------*/
    function do_output($sess)
    $f = fopen("text_file.txt");
fwrite($f, $sess['member_name'], $sess['ip_address'], $sess['timestamp']);
fclose($f);


I'm a complete newbie to php so please be easy on me smile.gif

Thanks in advance smile.gif

***wanted to add that I can't babysit the board 100% of the time so this will help tons.
Jaggi
IPB does this by default, you can check from your admincp for IP history of any member and you can check profiles to see when they were last active on the board. Also writing to a txt file on a busy forum could slow you down.
~Jacey~
It doesn't log the IP unless they post does it? Maybe I'm misunderstanding something. My board isn't all that busy. We normally have about 3-10 active members at peak times.
Jaggi
without looking through the code i can't 100% i know its linked to sessions but not sure when data is written but i know it definetly does it on post, login and settings changes... not sure on normal browsing tho.
~Jacey~
I'll make a test board and test this out.. thanks for your help smile.gif
Scott H.
IPB will only log an IP when someone registers (and validates), posts, votes and is emailing another member.

I'm not entirely sure why you want to log everyone's IP but I will warn you that this method will not exclude duplicates and you'll probably end up with a very large file very quickly. If you're looking to check certain IPs, most web hosts give you raw access stats which will log everything which happens on your site (although they'll usually auto-delete after a certain period of time).

If you still want to try your method, here is your code (slightly edited) which should work
CODE
  
function do_output($sess)
{
    $f = fopen("text_file.txt", "a");
fwrite($f, $sess['member_name'].", ".$sess['ip_address'].", ".$sess['timestamp']."\n");
fclose($f);
}


Finally, putting this in online.php won't do much help - as that is only called when someone visits the online list, so if you're sure you want to do this you'll need to put it in another file smile.gif
techteamgr
For high volume sites I do not suggest storing data for pageviews in a flat file. When it gets some MBs in size, it will need more and more resources (CPU, RAM) for being opened and written each time a page gets a hit. In this case the better solution is creating a table in your MySQL database

CODE
CREATE TABLE `pageviews` (
timestamp varchar(15),
ip_address varchar(20),
member_name varchar(30),
hostname varchar(50),
browser varchar(100)
);


and your php script:

CODE
mysql_connect("localhost", "username", "password");
mysql_select_db("database_name");

mysql_query("INSERT INTO pageviews ( 'timestamp', 'ip_address', 'member_name', 'hostname', 'browser' ) VALUES ( '$sess[timestamp]', '$sess[ip_address]', '$sess[member_name]', '$_SERVER[REMOTE_HOST]', '$_SERVER[HTTP_USER_AGENT]' )");

mysql_close();
Jaggi
i'd recommend adding member_id as a alternative or as well as member_name because if you change a members name you'll have problems finding them again.
xman
I am also looking for such a mod that will track this info.

I recently upgraded from 2.0.4 to 2.1.7. In the process of course lost all my mods I had installed. One was a security login mod that locked members out after x failed attempts. It showed all who logged in but not if a member had used the remember me option and then returned to the forum.

At that time I searched for a mod that would do as requested in this thread but couldn't find one.

Now I am looking once again for a mod that will do this but for version 2.1.x. Guess there isn't one out there yet. I know the security login mod has been updated for 2.1.x and may install that one anyhow but would rather a mod that tracked all the members (including their ip) instead of just ones who logged in.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.