Jump to content

Checking If Logged In Or Not(Different To My Other Post)


deathadder

Recommended Posts

Ok, so i have it working by setting the cookie time to 300 seconds(5 minutes), and i also have it so if you click logout it deletes cookie, and sessions + sets status field to offline, i also have a script in the config file that checks if the user has had any activity for the last 500 seconds, if it has it resets the time() for the user, if not it logs them out.

 

what im having trouble with is making a user online list, if they do not refresh their status will be set to online forever, can anyone help me here?

Link to comment
Share on other sites

Your database table that you are using to store the 'online' user information, needs to store the 'last access time' for each user. Then, when you are displaying the 'online' list, you only retrieve the records where the 'last access time' is within x seconds of the current time. Or you can just delete the records where the 'last access time' is older than x seconds from the current time and display the remaining records.

Link to comment
Share on other sites

EDIT: i have a problem, my previous theory did not work, so i retried what you said, i wrote up this code but it selects all users timestamps, and whenever one person does an action it uses that as previous action time for all.

 

<?
include 'config.php';
session_start();
$SQL = mysql_query("SELECT * FROM users");
$dbfield = mysql_fetch_assoc($SQL);
$inactive = 900;
$current_time = time();
$prev_time = $dbfield['timestamp'];
$query = $current_time - $prev_time > $inactive;
$SQL2 = mysql_query("SELECT * FROM users WHERE timestamp = '$query' AND online='online'") or die(mysql_error());
$dbfield2 = mysql_fetch_assoc($SQL2);

$count = mysql_num_rows($SQL2);
echo $current_time - $prev_time;
echo '<br />';
echo $count;
?>

 

 

here is the code, can you please tell me what i need to do to fix this?

Link to comment
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.