PHP/MySQL question

Discussion in 'Technology' started by trance_fan, Jan 21, 2007.

Users Viewing Thread (Users: 0, Guests: 0)

  1. trance_fan

    trance_fan Registered User

    Joined:
    Nov 7, 2002
    Messages:
    9,079
    Likes Received:
    0
    PHP/MySQL question

    I'm currently making an IT support logging system for the company I worked at during my placement.

    When a user logs in, I want to show some statistics - including number of logins, and a "you last logged in on: .." feature.

    Im wondering how to store this data?

    Will the number of logins be done by say having a login variable which will be initially set to 0, and then somewhere in the login script having an update query that increments this value by one? then simply echoing this variable.

    And in terms of the date...i was thinking that you would write a timestamp to the users table and then echo this on next login...but i was wondering in that case how to stop it from simply showing the timestamp it just recorded?

    cheers!
  2. 1615634792921.png
  3. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    The number of logins..

    Could you not just add a field called "logins" then refer to this in a variable.. then when the users logs in simply increment the value by 1?

    for example..

    I = "logins"

    OnSubmit I = I+1

    Or something similar.

    The timestamp..

    Just use a datefield and simply allow it to overwrite the date entry.

    I've not had much sleep so this may be a little vague but it might work.. It seems too simple though..
  4. Rob

    Rob Registered User

    Joined:
    Jun 5, 2006
    Messages:
    7,757
    Likes Received:
    3
    Location:
    Sancho Panza
    To do this you would create a login table.

    It would usually store the following

    user id
    timestamp
    ipaddress of login attempt
    Did the user give the right password?

    If you store all of that it's easy to calculate variables such as last login time, number of logins etc to display on a page.

    Hope that helps.
  5. trance_fan

    trance_fan Registered User

    Joined:
    Nov 7, 2002
    Messages:
    9,079
    Likes Received:
    0
    great stuff, searching for "login table" has given me a load of sample code...just the job.

    Cheers!

Share This Page