Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 10:53:39 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155556 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: display last login date and ip address  (Read 740 times)
Bug

Offline Offline

Posts: 188


« on: October 28, 2011, 05:41:01 PM »

Can anybody tell me wheter it is possible to add the previous login-date and ip address to the start.htt in the admin

I would like to display in the start.htt / admin/start/index.php:

welcome back 'John', the last time you logged in was '13 october 2011', you logged in with ip address 123.123.12.12

Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6977


WWW
« Reply #1 on: October 28, 2011, 06:13:34 PM »

There is a little Admin Tool called Userstatistics which does show the required Data. I don't see why you should not be able to implement the functionality you want based on this Admin Tool ...

cheers

Klaus
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

Bug

Offline Offline

Posts: 188


« Reply #2 on: October 28, 2011, 07:10:39 PM »

not really,


yes, the userstatistics module displayes the last login and last used ip address but as one logs in it will display that current logindate and current ip address...

I am looking for a way to display the previous login and previous-used ip address...

just like in most webmail-interfaces you see last time you logged in: 56-67-2014 with ip 123.123.67.67

I have a=got a customer who is very afraid his account will be hacked so he wants to see that he is the one that was logged in last-time and on his own ip address

I think this is not saved to the user-tables yet

if I make two extra database-fields
last_ip and last_login

can it be done that when you login, just bedore the new data is saved to login_when and login_ip the old existing data from those two fields is saved to the new fields?

that way i can display the previous login info ...




Logged
Bug

Offline Offline

Posts: 188


« Reply #3 on: October 28, 2011, 07:27:10 PM »

okay, found out where the login date and the login_ip is saved to the database

framework / class.login.php

original:
Code:
// Update the users table with current ip and timestamp
$get_ts = time();
$get_ip = $_SERVER['REMOTE_ADDR'];
$sql  = 'UPDATE `'.$this->users_table.'` ';
$sql .= 'SET `login_when`=\''.$get_ts.'\', `login_ip`=\''.$get_ip.'\' ';
$sql .= 'WHERE `user_id`=\''.$user_id.'\'';
$database->query($sql);

if I add a line to that file, something like:

Code:
// Update the users table with current ip and timestamp
$get_ts = time();
$get_ip = $_SERVER['REMOTE_ADDR'];
$sql  = 'UPDATE `'.$this->users_table.'` ';

                $sql .= 'SET `last_login`=\''.$login_when;.'\', `last_ip`=\''.$login_ip;.'\' ';

                        $sql .= 'SET `login_when`=\''.$get_ts.'\', `login_ip`=\''.$get_ip.'\' ';
$sql .= 'WHERE `user_id`=\''.$user_id.'\'';
$database->query($sql);

and add last_login and last_ip to the database,

something like this should work, am I right?

(i am probably doing it wrong but I cannot test right now as I am at home...)
« Last Edit: October 28, 2011, 07:39:40 PM by Bug » Logged
badknight
Moderator
**
Offline Offline

Posts: 246



WWW
« Reply #4 on: October 28, 2011, 07:35:43 PM »

if someone knows which file saves the ipaddress and login_when to the database I think I know how to accomplish what I need ...

framework/class.login.php
at line ~213:
Code:
// Update the users table with current ip and timestamp
$get_ts = time();
$get_ip = $_SERVER['REMOTE_ADDR'];
$query = "UPDATE ".$this->users_table." SET login_when = '$get_ts', login_ip = '$get_ip' WHERE user_id = '$user_id'";
$database->query($query);


Logged

Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...
Bug

Offline Offline

Posts: 188


« Reply #5 on: October 28, 2011, 07:40:49 PM »

thank you badknight, I found it too.. do you have an idea what I would need and how it can be done?
Logged
badknight
Moderator
**
Offline Offline

Posts: 246



WWW
« Reply #6 on: October 28, 2011, 07:49:51 PM »

hm.. the Problem is, if you modify something in this file.. you need to modify it by every update of the file!

but.. back to topic:

create a table in the Databse, you need id, userid, timestamp, ip
in the file admin/logout/index.php
you can add the SQL code to insert/update the fields in the database..

but the Problem is, if the user don't use the logout function the scripte don't work..
Logged

Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...
Bug

Offline Offline

Posts: 188


« Reply #7 on: October 28, 2011, 08:28:41 PM »

I do not doubt anyone expertise here, but i think it has to be different

I think it has to be in the login.class.php and not in the logout.class.php thing...

Logged
badknight
Moderator
**
Offline Offline

Posts: 246



WWW
« Reply #8 on: October 28, 2011, 08:46:10 PM »

no..

the login class only get includet, if the user logged in the system.. 
the logout is the last file is the last thing, what a user can see after his session get destroyd..

a alternative:

insert every login in the database, and chek the latest logins..

Logged

Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...
Bug

Offline Offline

Posts: 188


« Reply #9 on: October 28, 2011, 10:35:30 PM »

I do not get your reply, I want to save the ip and date from the previous time they logged in.

I just made the file I needed, all in the login.class.php, i will alter the start file and then when it works post the stuff I did

On the startpage I am going to display not only a welcome message as it is now but also extra info regarding the user

One of these things is the displaying of the last 5 ip addresses and the last 5dates the user has been logged in.

//
I do not care about the remark that it is not wise to alter the core files, if those files do not live up to the expectations they have to be made bigger and/or better!
Logged
badknight
Moderator
**
Offline Offline

Posts: 246



WWW
« Reply #10 on: October 28, 2011, 10:43:08 PM »


insert every login in the database, and chek the latest logins..



=> class.login.php

=> after
Code:
$query = "UPDATE ".$this->users_table." SET login_when = '$get_ts', login_ip = '$get_ip' WHERE user_id = '$user_id'";
$database->query($query);

your new code..
Code:
$query = "INSERT INTO => table <= (user_id, ip, timestamp) VALUES (USERID, IP, TIMESTAMP);
$database->query($query);
more information can you finde HERe

now, you have every login in the databse..
Logged

Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...
Bug

Offline Offline

Posts: 188


« Reply #11 on: November 04, 2011, 08:29:07 PM »

Did it, works great...

Anyone here that needs it?
Logged
dbs
WebsiteBaker Org e.V.

Offline Offline

Posts: 3719


WWW
« Reply #12 on: November 04, 2011, 08:39:50 PM »

yes, it is a nice feature. should be standard.
it creates many many entrys in the DB?
Logged

Bug

Offline Offline

Posts: 188


« Reply #13 on: November 04, 2011, 09:49:40 PM »

I now keep track of ten ip addresses and ten dates of these last logins per user...

I will upload the changed files tomorrow

Framework/login.class.php

Admin/start.php

To do it properly i should also change the templates/wb_admin/templates/start.htt but i had no time left and a just smashed it at the bottom of the admin/start.php...
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!