1
JBzh
How to log users connections into a text file (Newbie)
  • 2007/1/10 10:31

  • JBzh

  • Just popping in

  • Posts: 18

  • Since: 2004/4/26


I couldn't find a hack to log into a file the users connections/browsing. So I put the following in a file named logusernav.php :
<?php print "<!-- Beginning user log -->"; if ( !$xoopsuser ) { $user_to_log = "Anonymous usern"; } else { $user_to_log = "User ID: ".$xoopsUser->getVar('uid')."n"; } $content_to_log = $date('Ymd-H:i:s')." ".$user_to_log." n"; $log_file_name = XOOPS_ROOT_PATH.'logusernav.txt'; if (!$log_file_handle = fopen($log_file_name, 'a')) { echo "<!-- Cannot open file ($log_file_name) -->"; } else { if (fwrite($log_file_handle, $content_to_log) === FALSE) { echo "<!-- Cannot write to file ($log_file_name) -->"; } @fclose($log_file_handle); } ?>


But if I include it in the main index.php or footer.php it does nothing. It doesn't even print "Beginning user log".

I added :
le="color: #000000"><?php echo "<!-- nnn ----------------------include loguservnav ----------------nn -->"; include "logusernav.php"; echo "<!-- nnn ----------------------fin include loguservnav ----------------nn -->";

in footer.php just one line before the final "?>". It does add the comments, "include loguservnav" and the rest, but nothing from logusernav.php .

Can anyone give me a hint ? I'm curently connected to #xoopssupport and would really appreciate any help.

The logs I'm looking to obtain is :
[timestamp] userIP userid username url

I Hope I posted in the right place.

2
JBzh
Re: How to log users connections into a text file ? (Newbie)
  • 2007/1/10 17:02

  • JBzh

  • Just popping in

  • Posts: 18

  • Since: 2004/4/26


I made some mistakes, it works now.
It's pretty simple, I'm ashamed to bother the XOOPS community with my questions

Here is the thing, hopefully it will be usefull to someone :

File /xoops/html/logusernav.php :
<?php $ip_to_log = $_SERVER['REMOTE_ADDR']; $url_to_log = $_SERVER['REQUEST_URI']; if ( !$xoopsUser ) { $uid_to_log = "0"; $uname_to_log = "ANONYMOUS_NONAME"; } else { $uid_to_log = $xoopsUser->getVar('uid'); $uname_to_log = $xoopsUser->getVar('uname'); } $content_to_log = date('Ymd-H:i:s')." ".$ip_to_log." ".$uid_to_log." ".$uname_to_log." ".$url_to_log."n"; $log_file_name = XOOPS_ROOT_PATH.'/logusernav.log'; if (!$log_file_handle = fopen($log_file_name, 'a')) { echo "<!-- Cannot open file ($log_file_name) -->"; } else { if (fwrite($log_file_handle, $content_to_log) === FALSE) { echo "<!-- Cannot write to file ($log_file_name) -->"; } @fclose($log_file_handle); } ?>

Code to add at the end of /xoops/html/footer.php :
le="color: #000000"><?php include(XOOPS_ROOT_PATH."/logusernav.php");

It gives you the following logs :
le="color: #000000"><?php 20070110-16:27:46 192.168.1.124 0 ANONYMOUS_NONAME /xoops/html/index.php 20070110-16:28:27 192.168.1.124 5 jcoiron /xoops/html/index.php 20070110-16:29:16 192.168.1.124 5 jcoiron /xoops/html/ 20070110-16:29:18 192.168.1.124 5 jcoiron /xoops/html/modules/istats/ 20070110-16:36:45 192.168.1.124 5 jcoiron /xoops/html/ 20070110-17:42:02 192.168.1.124 5 jcoiron /xoops/html/modules/news/ 20070110-17:42:05 192.168.1.124 5 jcoiron /xoops/html/modules/news/article.php?storyid=1279 20070110-17:45:38 192.168.1.124 5 jcoiron /xoops/html/modules/xoopsmembers/

Warning ! This produce a lot of logs.

If you don't need to keep a record of everything your users do, the module UserVisit is probably what you're looking for :
http://sourceforge.net/project/showfiles.php?group_id=41586&package_id=105497&release_id=207281

3
irmtfan
Re: How to log users connections into a text file ? (Newbie)
  • 2007/1/11 8:54

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


nice code!
very useful for interanet purpose.

4
irmtfan
Re: How to log users connections into a text file (Newbie)
  • 2012/6/28 5:15

  • irmtfan

  • Module Developer

  • Posts: 3419

  • Since: 2003/12/7


Now it is the fifth year that i used this log in my website for log about 5 webmasters accounts activities.
make a new file named it logusernav.php and copy and paste below code:
<?php if ( $xoopsUserIsAdmin ) { $ip_to_log = $_SERVER['REMOTE_ADDR']; $url_to_log = $_SERVER['REQUEST_URI']; $uid_to_log = $xoopsUser->getVar('uid'); $uname_to_log = $xoopsUser->getVar('uname'); $content_to_log = date('Ymd-H:i:s')." ".$ip_to_log." ".$uid_to_log." ".$uname_to_log." ".$url_to_log."n"; $log_file_name = XOOPS_TRUST_PATH.'/logusernav.log'; if (!$log_file_handle = fopen($log_file_name, 'a')) { echo "<!-- Cannot open file ($log_file_name) -->"; } else { if (fwrite($log_file_handle, $content_to_log) === FALSE) { echo "<!-- Cannot write to file ($log_file_name) -->"; } @fclose($log_file_handle); } } ?>

then you can add this line at the end of your mainfile.php:

include XOOPS_ROOT_PATH."/logusernav.php";

and make a new file named it logusernav.log and locate it at xoops_lib directory.

I sent a feature request for a xoops history/log plugin here:
https://sourceforge.net/tracker/?func=detail&aid=3538328&group_id=41586&atid=430843

Please write your comments here or in the sf.net if you are interested.

urgently i want to find a way to eliminate the old logs automatically because the log file will be huge after some days. for example 5 days old logs deleted.


Who's Online

197 user(s) are online (141 user(s) are browsing Support Forums)


Members: 0


Guests: 197


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits