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
https://forums.phpfreaks.com/topic/26331-please-help-me/
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
https://forums.phpfreaks.com/topic/26331-please-help-me/#findComment-123949
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.