-1

I have an existing PHP MYSQL login system for a site. I want to record the history of every user login including failed attempts.

I want to capture the following data on the history:

  1. username used
  2. Time logged in
  3. Date logged in
  4. Successful - (answerable by yes or no)

How can I do this without changing my entire existing login system?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
PHPNewbie
  • 35
  • 3
  • 11
  • See http://stackoverflow.com/questions/580534/best-way-to-limit-and-record-login-attempts and http://stackoverflow.com/questions/6357609/limiting-the-number-of-failed-login-attemps – Sukumar Aug 04 '11 at 08:30

2 Answers2

6

Create a new table with that info and insert when user logins ...

CREATE TABLE `login_info` (
    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `username` VARCHAR( 50 ) NOT NULL ,
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
    `success` ENUM( 'yes', 'no' ) NOT NULL
);

I didn't understand why you need time and date separately ...

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
1

Looks like you need a basic understanding of OO code as well... Create a new table called login_info with fields as Mihai's answer then assuming your login method is a part of a user class - create a method that will insert a row into this table every time a login is attempted. For example :

class user {
    function login() {
        $this->login_attempt();
        // your login code
    }
    function login_attempt() {
        // insert into your login_info table
    }
}

This keeps your log separate from your login code.

Boz
  • 1,178
  • 1
  • 12
  • 26