Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to track the total number of logged in members

    I am currently working on a membership based web site. I need to display the number of members

    logged in that system. To do this I have set a flag in the database which is set to 1 whenever a

    user is logged in the system and when the user clicks on the ‘Log Out’ link a query is fired that

    sets the same flag to 0. To display the total number of logged in members I run a query that counts

    the number of records whose flag is set to 1.

    However this method has a major shortcoming. When users do not click the ‘Log Out’ link but just

    close the browser. In such a situation the query that will set the flag field back to 0 will bot be

    fired and hence the user would be seen as active in the system even though the user has already left

    the system.

    When one company is viewing the profile of another company in my site I also need to show whether

    that representative of the company whose profile is being viewed in logged in the system at that

    time or not so that if the user wants then can send a message to them.

    I need some advice on how can I achieve this in the best possible way, where I can display the total

    number the total number of correct logged in members

    Thanks a lot!

    Cheers
    Paresh

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    However this method has a major shortcoming. When users do not click the ‘Log Out’ link but just close the browser.

    Couldn't you set again flag to '0' only when they click logout or COOKIE time-limit, say 24 hours or 1 week expires.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe each time a logged in user clicks a page in the site a timestamp is added to the database showing the time of their last action. Then set a maximum time limit and, if the last action occured more than X minutes ago show that user as logged out. That way if they're not really logged out, as soon as they start browsing again they will be shown as logged in.

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    190
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by delinear
    Maybe each time a logged in user clicks a page in the site a timestamp is added to the database showing the time of their last action. Then set a maximum time limit and, if the last action occured more than X minutes ago show that user as logged out. That way if they're not really logged out, as soon as they start browsing again they will be shown as logged in.
    this is the way i used. i just ran an update set table last_login = '".time()."' query when they logged in. then when i pulled the list my query was SELECT * FROM table WHERE last_login < '".$new_time."' and i set $new time = to time()-(15*60);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •