Zubrag.com
September 23, 2018, 02:19:37 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Retrieving log-in data  (Read 12150 times)
roynlper
Newbie
*
Posts: 1


« on: January 05, 2008, 08:36:02 AM »

Hi,

I have just come across your wonderful site ......never seen so many satisfied customers before  : Smiley

I have just downloaded the advanced password protection script as it appears to be just what I have been looking for.

One of the features I am looking for is to be able to retrieve a record of users logged in/out including date/time.

Is this possible within the script as is (not installed it yet) or can the script be modified to accommodate?

Many thanks
Roy

Logged
recoding
Global Moderator
Jr. Member
*****
Posts: 71


WWW
« Reply #1 on: July 02, 2008, 04:35:32 PM »

I presume so Give me a sec I need to check the script again...

Yea it seems possible, might need to check with Zubrag first,
in the password-protect.php look for this:
Code:
// user provided password
if (isset($_POST['access_password'])) {

  $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
  $pass = $_POST['access_password'];
  if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
  || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
  ) {
    showLoginPasswordProtect("Incorrect password.");
  }
  else {
    // set cookie if password was validated
    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
   
    // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
    // So need to clear password protector variables
    unset($_POST['access_login']);
    unset($_POST['access_password']);
    unset($_POST['Submit']);
  }

}
Once found, underneath where it says setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); add this:
Code:
$counterfile = "log.txt";
$time = $GMT[hours] . ":" . $GMT[minutes] . " ";
$date = $GMT[mday] . "/" . $GMT[mon] . "/" . $GMT[year];
$fp = fopen($counterfile, "a");
fwrite($fp, " " . $login . " - " . $time . $date . "\n");
fclose($fp);

What this should do is save the login username and the time + date of login to a file called log.txt [change to the one you want] and then jsut keep doing that to a new line
Crude but works, I can construct a MYSQL one, but I get the feeling you might not even read this, but hey, I helped, and I think it works Smiley

-Dan.
Logged

ray985
Newbie
*
Posts: 4


« Reply #2 on: February 09, 2009, 01:40:27 PM »

I know this post is kind of old, but it's the closest thing I found to an answer on this board. I've tried to implement the suggested code, but when I look at the generated text file, all I get is

  - : //

Am I doing something wrong?
Logged
recoding
Global Moderator
Jr. Member
*****
Posts: 71


WWW
« Reply #3 on: February 09, 2009, 03:01:55 PM »

Ew my code >:
update what i added to:
Code:
$fp = fopen("log.txt", "a");
fwrite($fp, "• " . $_SERVER['REMOTE_ADDR'] . "(" . $user . ")" . " - " . date("d/m/y H:i:s") . "\n");
fclose($fp);

Give me a sec and i'll update it, that will currently show the times, but not the IPs/Users.

UPDATE: Okay, it will show the IPs of the users, just not the usernames...i'll post again once I work that one out.


Logged

recoding
Global Moderator
Jr. Member
*****
Posts: 71


WWW
« Reply #4 on: February 09, 2009, 03:13:33 PM »

Final update to save/log the logins.
Code:
$fp = fopen("log.txt", "a");
fwrite($fp, " " . $_SERVER['REMOTE_ADDR'] . "(" . $_POST['access_login'] . ")" . " - " . date("d/m/y H:i:s") . "\n");
fclose($fp);

How it works:
$_SERVER['REMOTE_ADDR'] = The users IP address
$_POST['access_login'] = If you look at the source of the page, you will see that the username is called 'name="access_login' thats how this works.
date("d/m/y H:i:s")=
d - Day of the month, 2 digits with leading zeros
m - Numeric representation of a month, with leading zeros
y - A two digit representation of a year
H - 24-hour format of an hour with leading zeros
i - Minutes with leading zeros
s - Seconds, with leading zeros


Logged

ray985
Newbie
*
Posts: 4


« Reply #5 on: February 10, 2009, 10:23:46 AM »

Thanks, seems to be working ok so far, although it only registers when I log into the manage.php application. I'm thinking it's a problem with the protection setup on my other pages, so I'm working on that now.
Logged
recoding
Global Moderator
Jr. Member
*****
Posts: 71


WWW
« Reply #6 on: February 10, 2009, 11:11:44 AM »

You have to make sure that they are in the same folder, else change
Code:
$fp = fopen("log.txt", "a");
to
Code:
$fp = fopen("/path/to/where/the/log/is/log.txt", "a");
So that it always writes to the correct log
Logged

ray985
Newbie
*
Posts: 4


« Reply #7 on: February 10, 2009, 03:10:00 PM »

I found the problem, I was inserting the code into the password_protect.php but that seemed to be the login for the administrator site. When I added the code to the login.php instead, it works like a charm. Thanks so much!
Logged
Surao
Newbie
*
Posts: 7


« Reply #8 on: February 23, 2009, 05:17:40 AM »

Is there anyway of logging logout information as well, and customising the Time log to my time zone thats GMT +7.

Thanks


Logged
recoding
Global Moderator
Jr. Member
*****
Posts: 71


WWW
« Reply #9 on: February 23, 2009, 07:39:22 AM »

There is a problem with logging logout times, the logout command technically is on the client..meaning the server never knows if the user is still logged in, the server adds the cookie when the user logs in, and then the client deletes the cookie when they close their browser window..I'm not sure on a way how to log them logging out.

For the GMT setting, this is set up on your server, for example I have a UK server so it is set to GMT, however other servers in other areas should have the respective timezone settings.

However if you want to use a hack, please try this (Ref: [TYPO3] MailLists):
Code:
$time = $GLOBALS['TSFE']->page['SYS_LASTCHANGED'];
$hour = date (G,$time);
$day = date('d',$time);
$month = date ('m', $time);
$year = date ('Y', $time);
$fp = fopen("log.txt", "a");
fwrite($fp, " " . $_SERVER['REMOTE_ADDR'] . "(" . $_POST['access_login'] . ")" . " - " . date("d/m/y H:i:s",mktime($hour+7, 0, 0, $month, $day, $year)) . "\n");
fclose($fp);

However, I'm not sure if this would work as I am unable to test it here.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC