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 271321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:08:34+00:00 2026-05-12T00:08:34+00:00

Is there a way I can piggy back sessions to know if the user

  • 0

Is there a way I can piggy back sessions to know if the user is online?

I.e: use logs on, I set a $_SESSION variable, user times out- cookie Garbage collector updates the database to update their status as offline.

EDIT: I want a solution that does not involve times or dates. I want something to ride on sessions or something similar. Guessing if someone is online is not good enough for what I need.

  • 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-05-12T00:08:35+00:00Added an answer on May 12, 2026 at 12:08 am

    Don’t bother with figuring out the differences between time zones—that’s not necessary.

    Whenever the user accesses a page, set/update a lastActiveTime field in their record of the Users table. Then, do a COUNT for all users having a lastActiveTime within the last 5 minutes. Anything more than this, and they can be considered "offline."

    If you use your server-time, via the NOW() function in MySQL, you’ll avoid the need to deal with time zones. This is the standard way of tracking how many users are presently online (meaning, active within the last x minutes).

    Constantly Updated

    If you would like to know they are still active (even when they’re not jumping from page to page), you could include a bit of JavaScript to ping your server every 60 seconds. It’ll work the same way as my original suggestion, but it will update your records without requiring users to be frantically browsing your site at least once every five minutes.

    Original 2009 Code

    var stillAlive = setInterval(function () {
        /* XHR back to server
           Example uses jQuery */
        $.get("stillAlive.php");
    }, 60000);
    

    Updated 2022 Code

    We can use fetch and promises today to more precisely issue these calls. Fetch will replace our earlier XHR approach using jQuery. Fetch returns a Promise, which we’ll use (via the await keyword) to defer timing of our next call. Once the call to stillAlive.php is complete, and a response has been retrieved, we’ll setup the next ping for 60 seconds later.

    (async function ping () {
        // Asynchronously call stillAlive.php
        await fetch( "stillAlive.php" );
        // Issue this call again in 60 seconds
        setTimeout( ping, 60_000 );
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way I can set a formatter on models that will convert
Is there a way I can use one category to stylize all of my
Is there any way I can use JPA or hibernate annotations to specify the
Is there a way I can give developers permission to grant a user permissions
I was wondering is there can be a way to stringize an integer variable
Is there any way I can get NHibernate to use the READPAST hint when
Is there any way I can use the GIT cli to figure out how
is there any way i can mimic javascripts loose variable handling in php? for
Is there any way can declare a bean in just like JSP UseBean in
Is there way that I can read the file from remote server using fopen

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.