Need Help For Last Visit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chaos
    New Member
    • Jun 2007
    • 52

    #1

    Need Help For Last Visit

    Hi all , I need help on how to do a last visit update to find the previous login date and time of the user.
  • abertay
    New Member
    • Jul 2007
    • 10

    #2
    Originally posted by chaos
    Hi all , I need help on how to do a last visit update to find the previous login date and time of the user.

    You can do that with the help of Cookies.

    Comment

    • chaos
      New Member
      • Jun 2007
      • 52

      #3
      Originally posted by abertay
      You can do that with the help of Cookies.
      Gt any example how to use the cookie???

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Originally posted by chaos
        Hi all , I need help on how to do a last visit update to find the previous login date and time of the user.
        If this is on a system where you store the user details in a database you can also store the date and time of the visit. So when the log in again you can check when they last visited display any information you need to based on that and then log the new visit date and time.

        This way doesn't rely on cookies which may be switched off on the user side of things.

        This is the way I would do it, as the data is more permanent. Even if the user has cookies on they can clear them out so you loose the information about their last login. Storing it in the database means you have contorol over the data you need.

        Cheers
        nathj

        Comment

        • chaos
          New Member
          • Jun 2007
          • 52

          #5
          Originally posted by nathj
          If this is on a system where you store the user details in a database you can also store the date and time of the visit. So when the log in again you can check when they last visited display any information you need to based on that and then log the new visit date and time.

          This way doesn't rely on cookies which may be switched off on the user side of things.

          This is the way I would do it, as the data is more permanent. Even if the user has cookies on they can clear them out so you loose the information about their last login. Storing it in the database means you have contorol over the data you need.

          Cheers
          nathj

          wt will be the code like???

          Comment

          • nathj
            Recognized Expert Contributor
            • May 2007
            • 937

            #6
            Originally posted by chaos
            wt will be the code like???
            Hi,

            First of all you need a database with a table in it that stores the user credentials.

            Second you need a login page. This normally includes a form with a post method. The desitination page, as set by the action on the form, would check the credentials entered are for a valid user and if so when they last logged in. If the credentials are invalid then you need to report in this to the visitor.

            Third, based on the the current time and the last logged in time the user who sucesfully logs in can be presented with a specific message. This would go on the the page the login form specifies as the form action.

            That's the general principle. I will be doing something like this very shortly but that the design I have mapped out. I am not going to write my module and then give you the code, however if you have a go and post any code you get stuck with I will help out.

            It is worth reading through some tutorials on php and database:
            Data Abstraction Layer
            W3Schools

            These are both excellent, I use them all the time.

            Cheers
            nathj

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              A quick way is to make your user table have two more columns for the latest login time and the last login time. Then, you could update it simply whenever users log on:

              [code=php]mysql_query("UP DATE `user` SET `lastLogin` = `latestLogin`, `latestLogin` = " . date('Y-m-d H:i:s') . " WHERE `username` = '" . $username . "' AND `password` = '" . $password . "';");
              if(mysql_affect ed_rows())
              {
              // login credentials were correct
              }[/code]

              Comment

              • chaos
                New Member
                • Jun 2007
                • 52

                #8
                Originally posted by volectricity
                A quick way is to make your user table have two more columns for the latest login time and the last login time. Then, you could update it simply whenever users log on:

                [code=php]mysql_query("UP DATE `user` SET `lastLogin` = `latestLogin`, `latestLogin` = " . date('Y-m-d H:i:s') . " WHERE `username` = '" . $username . "' AND `password` = '" . $password . "';");
                if(mysql_affect ed_rows())
                {
                // login credentials were correct
                }[/code]
                In if(mysql_affect ed_rows())
                {
                // login credentials were correct
                }
                wt should i put for the login credentials

                Comment

                • chaos
                  New Member
                  • Jun 2007
                  • 52

                  #9
                  how to capture the time when the user login and pass the time into the lastvisit field of the user_profile??? ?

                  Comment

                  Working...