954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to get login and logout time of User..?

just a small query...

how to get User's login time and logout time...???
as well as how to know whether particular user in Logged in out..??


Thnx

nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

You can get the current timestamp from the time function and parse it to a date through the use of the date function. If you do this when the user logs in or out and store it in your database, you can then retrieve this information quite easily. Have a try and post an attempt, then we might be able to give you some more pointers.

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

okay...
.
.
but how to get logout time..??
.
.
what to do when user closes the broswer instead of logout...
.
.
i uses insert query on login to get login time with help of now function of mysql...!!
.
.
but i dont understand what to do on logout..!! though i uses update query on logout... but i m confused what to do when user closes the browser..?? :(

nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

nish123, you need to do research before posting here all the time!!!

For a timestamp like suggested by "darkagn" you would use the date() function supplied by php.
Go to www.php.net to learn more.
You then would follow this logic
- You would store that value
-- Storing it in a database or a session (which you should have researched in your previous thread)
- Then retrieve it as required

Let me know how you go once you do some research.

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

Basicly the logic is like this, :P
You take the time stamp when they log in, store this in two fields last log in time and last movement.

Every page they visit you need to runa query to update their last move to the current time stamp.

Most systems use 5 minutes so I will to.

$timestampFromTable = "sometimestamp";
$timenow = time();

$lastMove = $timenow - $timestampFromTable;

$fiveMins = 60*5;

if( $lastMove > $fiveMins ) {
    echo "User not logged in...";
} else {
   echo "User is logged in";
}
Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

when time is echoed what format is used?

I usually use date as I can specify the format I wish to use?

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

when time is echoed what format is used?

I usually use date as I can specify the format I wish to use?

But you store it as a timestamp right?

Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

when time is echoed what format is used?

I usually use date as I can specify the format I wish to use?


time() returns the unix timestamp, you have to use strftime to convert it to a human readable date

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

just a small query... how to get User's login time and logout time...??? as well as how to know whether particular user in Logged in out..?? Thnx


Answer:

When we press the Login button on that time you can note down the time using timestamp method and store it into the table for reference and same with logout. means just check when we press the button , save the time in a veriable and store it into the database for later use

rahul.anand77
Newbie Poster
10 posts since Sep 2008
Reputation Points: 8
Solved Threads: 0
 

Basicly the logic is like this, :P You take the time stamp when they log in, store this in two fields last log in time and last movement.

Every page they visit you need to runa query to update their last move to the current time stamp. (...)

I quote this reply to put forward some questions:
1) an approach like that (with an update query) is not slowing down the website? It's not better to save last move in sessions?
2) is there a way to save a timestamp when the user closes the browser w/o logging out or uses the same tab to visit external sites showing he's in fact left our website?

BigFormat
Light Poster
45 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

You could but this would involve JS and would be avoidable then you would have 100's of people logged in when their not.

As long as you have a decent host it shouldn't effect the server. And as for saving the last move in the session it is difficult to take data from the sessions, something I have never done.

I have always used this method and it hasn't made the site laggy at all and full fills it's purpose. :)

Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

I love how you guys have just taken over the poor man's thread... haha
I think his disappeared anyways... lol

Best way imo, sessions and then if required outside of user login/logout database, but I doubt there would be very many scenarios that would 'require' it maybe just a little feature but session the way to go, agreed?

OmniX
Practically a Master Poster
656 posts since Dec 2007
Reputation Points: 31
Solved Threads: 10
 

I love how you guys have just taken over the poor man's thread... haha I think his disappeared anyways... lol

Best way imo, sessions and then if required outside of user login/logout database, but I doubt there would be very many scenarios that would 'require' it maybe just a little feature but session the way to go, agreed?

Nope, disagreed. :)

I just siad no. I have actually looked into it and as far as a know you can't retreive cookies from users to decide wether they are on or not.

You would have to run a query to tell the sql db that the user (that just changed a page) is online. Then give it a timestamp and then run a query when displaying online users saying:

// 360 = 5mins
if( $row['timestamp'] > ( time() - 360 ) ) {
echo "Online";
} else {
echo "Offline";
}
Josh Connerty
Posting Whiz
342 posts since Apr 2009
Reputation Points: 31
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You