abdfahim Posted November 13, 2007 Share Posted November 13, 2007 How can I know that when a user is logged in? Like I want to store each login and logout time of each user in a database. Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 13, 2007 Share Posted November 13, 2007 Create a timestamp when they log in and another when they log out. When they log out subtract the first timestamp from the second, giving you the amount of seconds they were logged in for then update the database with that. You could then use date() (I think) it may be time(), to change the timestamp into something more readable. I'm not sure if it's date() or time() or maybe even something else, working with dates and times in PHP is something I've not entirely grasped myself yet, someone else could probably help you more... Quote Link to comment Share on other sites More sharing options...
cmgmyr Posted November 13, 2007 Share Posted November 13, 2007 What I usually do is have a "last_login" (date_time) in my users table. When the user logs in I just update this with NOW(). If you want to calculate how long your users have been logged into your site check this out: http://www.bytemycode.com/snippets/snippet/736/ I wrote that for a few of my sites and it works well. Hope that helps! -Chris Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 14, 2007 Author Share Posted November 14, 2007 Well .. when user login or log out manually, then its very easy to collect time. But my problem is, if any one cross the browser window instead of clicking on logout button, then what happens? How can I catch the timestamp of that moment? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 14, 2007 Share Posted November 14, 2007 create a session that creates your timestamp and if the user closes the window, the session will be destroyed and then create a timestamp once the session is destroyed. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 14, 2007 Author Share Posted November 14, 2007 can you plz tell me how can I create a timestamp when session is destroyed due to closing of window? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 14, 2007 Share Posted November 14, 2007 create an ajax script that will be queried on unload Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 14, 2007 Author Share Posted November 14, 2007 thanx man ... I am now searching on Ajax script. I didnt hear it before !!! thanx again. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted November 14, 2007 Author Share Posted November 14, 2007 I can't make it .... plz give me some sample code or helpful link.. I want to detect when (the time) an user leave my website either by closing window or typing another address in address bar. Quote Link to comment Share on other sites More sharing options...
nuxy Posted November 14, 2007 Share Posted November 14, 2007 AjaxFreaks.com has allot of helpfull tutorials on ajax. And Aureole gave you a good example, aswell as cmgmyr. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.