php loginn time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imran ansari
    New Member
    • Mar 2008
    • 1

    php loginn time

    hi
    i want to know how can i calculate the time difference b/w login time and logout time in php.
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by imran ansari
    hi
    i want to know how can i calculate the time difference b/w login time and logout time in php.
    Save the time in database.
    To get time, use gettimeofday()

    Comment

    • VinniemacND
      New Member
      • Mar 2008
      • 13

      #3
      Originally posted by hsriat
      Save the time in database.
      To get time, use gettimeofday()
      Alternative way:
      If you don't feel like modifying the table structure, you could instead store the login time in a session variable, and when the user logs out, just subtract the login time session var from the current time (logout time).

      When the user logs in, you could do

      [PHP]session_start() ;
      $_SESSION["login"] = time();
      // rest of code[/PHP]
      When the user logs out:

      [PHP]session_start() ;
      $timepass = time() - $_SESSION["login"];
      // continue logout
      [/PHP]

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by VinniemacND
        Alternative way:
        If you don't feel like modifying the table structure, you could instead store the login time in a session variable, and when the user logs out, just subtract the login time session var from the current time (logout time).

        When the user logs in, you could do

        [PHP]session_start() ;
        $_SESSION["login"] = time();
        // rest of code[/PHP]
        When the user logs out:

        [PHP]session_start() ;
        $timepass = time() - $_SESSION["login"];
        // continue logout
        [/PHP]
        What if the user doesn't log out?

        Comment

        • VinniemacND
          New Member
          • Mar 2008
          • 13

          #5
          Originally posted by markusn00b
          What if the user doesn't log out?
          True, guess the really only application of my alternative is if he simply wants to display the amount of time the user was logged in upon logout :-/

          Comment

          Working...