Jump to content

Recommended Posts

Hi,

I'm creating a membership section where once a member logs in, an entry is created in the "onlinenow" table. And I use that info to display who is online in a small box on the home page.

 

When they physically logout, the logout page erases that entry in the "onlinenow" table.

 

BUT if the user isn't active for a while the session expires but the entry in the table obviously stays intact, so it looks like they are still online.

 

Can someone tell me how to fix this issue? Or if there is a better way to show who's online now instead of a separate table that logs logins?

 

I've searched google for an answer but the discussions about sessions seem kind of over my head at this point...

 

Thanks..

Link to comment
https://forums.phpfreaks.com/topic/242688-session-logout-time/
Share on other sites

If the sessions aren't time based (they end when the user closes the browser), you'll have to make up a time. Usually something like now+5 minutes.

 

Basically the logic is:

 

User does action. User marked active at this time.

 

Find all users active within the last X minutes. (These users are considered online.)

You could add a buffer zone as well. Users within 5 minutes = online. Users within 5 - 10 minutes = idle.

Link to comment
https://forums.phpfreaks.com/topic/242688-session-logout-time/#findComment-1246513
Share on other sites

i guess mine are automatically time based because if i leave the browser open long enough, the session will expire, but I still don't get how to set a certain amount of time and how to cause a check and then get rid of that onlinenow entry in the table after that?

 

:-(

Link to comment
https://forums.phpfreaks.com/topic/242688-session-logout-time/#findComment-1246517
Share on other sites

Here is what I would do:

 

<?php
    session_start();
    // Do all user login validation

   Blah blah blah validation code.

   // User is now active. Update user time.
   $timeout=date("YmdHis", strtotime("+5 minutes"));

   $sql="UPDATE table SET onlinenow = '{$timeout}' WHERE ID = userID";
   @mysql_query($sql);

   $now=date("YmdHis");
   // Get all online users:
   $sql="SELECT * FROM table WHERE onlinenow > '{$now}'";
   -- Loop through all online users here and do what you want with them.
    
?>

Link to comment
https://forums.phpfreaks.com/topic/242688-session-logout-time/#findComment-1246519
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.