PDA

View Full Version : Checking for current userid is live or not


Spec_tray
02-05-2008, 08:44 AM
Hai there..

I have a situation here..Please try to help me

For checking user is live or not i am saving "Y" in my table when user logged in and updating same field when user logged out as "N".

In normal it works fine if user logging out proper way and when session timeout occurs also...

But if they close browser window or they leaves the page ....I cannot do this process.result when user trying to log in next time it shows as user is currently logged in...

how can i do that..or any alternative way to do that ?

regards

angst
02-05-2008, 05:29 PM
ok, i do something like this on a few of my sites,
the best thing to do is to update a DATE_TIME field in your data base every time a user hits a page IF they are logged in,

then you can simply use an SQL statement with the INTERVAL function to get users actiev with in the last 5 or 10 minutes, or whatever time range you want.

example: WHERE LastLoginTime > date_sub(CURRENT_TIMESTAMP , INTERVAL 5 MINUTE)

Spec_tray
02-06-2008, 07:20 AM
hai angst...

Thanks for providing a good solution for my prob.just one more clarification from your example.

i.e

WHERE LastLoginTime > date_sub(CURRENT_TIMESTAMP , INTERVAL 5 MINUTE)

I am assuming this is for the checking i have to done when user is trying to log in...right ?

regards

angst
02-06-2008, 03:13 PM
you would run that check after login to see how many users are currently online.
and make sure that everytime a logged in user hits a page to update the Date_Time field on the data base.

Spec_tray
02-07-2008, 10:04 AM
Hai Thanks ...

Thank you for this solution angst...i hope i will solve my problem using this method..

regards