Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:55:12+00:00 2026-06-04T07:55:12+00:00

I’ve binged a lot for this stuff, but couldn’t find direct ANSWER, I’ve searched

  • 0

I’ve binged a lot for this stuff, but couldn’t find direct ANSWER,
I’ve searched for this here,

But
I am still beating my head against the wall trying to implement,

How do I do update query after session expired?
I’m not talking about explicit clicking “Logout” button

Here’s basic SQL structure:

CREATE TABLE auth_users (

 email       varchar(40) NOT NULL,
 password    varchar(40) NOT NULL,
 online      ENUM('1') DEFAULT NULL  <-- HERE, it updates to 1 when user logged in, it updates back to NULL when user explicitly clicks on LOGOUT

) type=MyISAM;

Class Hierarchy:

interface {
    function login();
    function logout();
        //calls after succes authorization
        function set_as_online();
        //calls from within logout() method
        function set_as_offline();
}

BUT IT DOES NOT UPDATES BACK TO NULL WHEN USER CLOSES HIS BROWSER,

For example,
Assume we have two users: User-A, User-B

User A logged successfully, now User-B can see User-A as ONLINE user.

If User-A forget to click “LOGOUT” and would close his browser,
user-B still can see User-A as ONLINE. That’s the problem.

For example,
Facebook handles this very well,

Assume your friend just closed the browser (i.e his session does not exists anymore),
then somehow you can see him as OFFLINE

What am I doing wrong? Incorrect approach of handling offline/online users?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:55:14+00:00Added an answer on June 4, 2026 at 7:55 am

    Another approach is needed here i think. Don’t set a online/offline flag, but a ‘last_seen’ timestamp. Ie. with every request update the record to the current timestamp. If you want to know if the user is online, just do:

    if($current_time - $last_seen_time < $session_expire_limit) {
        // online
    } else {
        // offline
    }
    

    Otherwise you’d need a cronjob of some sort to automatically reset the online flag in your database after a certain time, but then still you’d need a last_seen column.

    // edit

    i don’t know exactly how facebook does it, but it could be one of the following; for the chat and notify functionality facebook opens up a ‘stream’, which is in fact a little ajax call which is kept alive by the server (btw, this ajax call is refreshed every 40 seconds). Possibly this stream is used to track online users. Another option, but less likely, is that an event is attached to the window.unload event. This is less likely because a page refresh, a clicked link to another facebook page etc. is also triggering the event. This would mean that every time an internal facebook link is clicked the event should be unbinded from the browser.
    Can’t think of another way atm, just some suggestions. Unfortunately those are quite labor-heavy to implement, I assume my suggestion above (before the edit) should be suitable for a common website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.