Jump to content

Please help me


schme16

Recommended Posts

I've made a website (http://josef-stalin.com but its not about him dont worry) and i've set it so that when a user logs in it sets a value in the users table data to "online" and for a list of people with this value to be shown on the site.

My Question is, how can i make my website set that value to "offline" when the user closes the browser or navigates away from my domain.... or if its easier, how can i set it so that after about 30mins the cookie timesout (but i'd need to be told how to make this way set the value to offline when the cookies has timed out)


any help is greatly appreciated!
Link to comment
Share on other sites

The easiest way is to have a timestamp in this table that gets updated evrytime the user hits a page. You then need to run a cron job every minute or whatever to check to see how old the timestamp is. If its oler than say 5 mins, you could set the user as offline.
Link to comment
Share on other sites

Thanks for the conceptual base upon which i wrote the code (I'm a person that has to understand the process in order to create it...come people can create without knowing that...but often I can write exceptionally when I have thought out what it is being done)...

The code I ended up using (for anyone else out there who needs help) is:
[code]

if (($logged[username]) != (NULL))
{
$update = mysql_query("Update users set timestamp = '$realtime' where username = '$logged[username]'");
}
//This strips the user of their online status if the've been 'offline' for x minutes.

$getuser = mysql_query("SELECT * from users");
while ($user = mysql_fetch_array($getuser))
{
$sumtime =(($realtime) - ($user[timestamp]));

if ($sumtime > 300)
{
$update = mysql_query("Update users set online = 'false' where username = '$user[username]'");
}
}
//this is for the offlinners to get re-instated as online.
$getuser = mysql_query("SELECT * from users");
while ($user = mysql_fetch_array($getuser))
{
$sumtime =(($realtime) - ($user[timestamp]));

if (($sumtime < 300)  and ($user[loggedout] == 'false'))
{
$update = mysql_query("Update users set online = 'true' where username = '$user[username]'");
}
}




[/code]

Variable List:
$realtime = time();
$logged is the persistence of the users settings(table values)
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.