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

Recommended Answers

All 12 Replies

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.

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, 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.

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";
}

when time is echoed what format is used?

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

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?

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

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

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?

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. :)

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?

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";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.