Jump to content

Users online script


AbydosGater

Recommended Posts

Hi, Im working on a users online script...

So far im only trying to get the script to know if there is a row with the members_id in the database..
All the sessions are set and database is connected and everything...

I am currently using the following code..
[code]
<?php
//Now we do the checks for the useronline program
$member_id = $_SESSION['user']['member_id'];
$userrowinonline = mysql_query("SELECT * FROM sf_usersonline WHERE member_id='$member_id'");
if ($userrowinonline == true){
echo "User is online";
} elseif ($userrowinonline == false){
echo "not online";
} else {
echo "System Error: Users online script failed.";
}

?>
[/code]

and ehhh that doesnt seem to work keeps passing as true... anyone have any better ideas..

Last thing.. I was wondering about the timeout.. if i insert to the database with each user a time()...

How would i set it up to delete a user whos time is less then 20 minutes or something?

Thanks Abydos
Link to comment
https://forums.phpfreaks.com/topic/28881-users-online-script/
Share on other sites

what I do is set a few things in the online table.

id, user_id, user_ip, user_time (and sometimes user_sesid)

When they log in, add all this information into the database. And make sure when they log out that this gets deleted or you have a field like "user_online enum('on','off')" and then when they log out turn it 'off' but u can keep the online info for "Online Today" tables maybe.

You can save the time with UNIX_TIMESTAMP() and figure up 20 minutes in unix time. it's something like 1200 I think (but i'm probably wrong) so to check you can do something like:

if((time() - $user_time) < 1200){
// if time now minus time when logged in is less than 20 minutes

// DO WHAT YOU WANT

}

now that may not be exactly right but it's close lol.. gives u an idea

Link to comment
https://forums.phpfreaks.com/topic/28881-users-online-script/#findComment-132216
Share on other sites

Thank you sooo much..

Ok afetr lots of coding i have it working,,
Its inserting when users login..
Deleting after 5 idle minutes...
and updating on refresh

But not good enough :P
When i updated my logout.php to include..


$member_id = $_SESSION['user']['member_id'];
unset($_SESSION['user']);
mysql_query("DELETE FROM sf_usersonline WHERE member_id='$member_id'") or die(mysql_error());


But thats not working, not deleting the record when user logs out and no mysql error :( any ideas why?
Link to comment
https://forums.phpfreaks.com/topic/28881-users-online-script/#findComment-132338
Share on other sites

try to change this section:
member_id='" . $member_id . '"

And if that doesn't work then my usual debug thing to do is use die() to determine if $member_id has any value. So if this doesn't work add die($member_id); above the unset session area.

You might want to try using $_SESSION['member_id']; instead too
Link to comment
https://forums.phpfreaks.com/topic/28881-users-online-script/#findComment-132343
Share on other sites

Wait i just tryed echoing the $member_id.. and thats the error, its displaying the first letter of the users username not the member id! its the same with all accounts.. why is this?

edit: i echoed this on another file, and its displaying the read member_id but not on the logout script
Link to comment
https://forums.phpfreaks.com/topic/28881-users-online-script/#findComment-132351
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.