Zepo. Posted December 2, 2007 Share Posted December 2, 2007 Is there any tutorials on this? Liike it will list the users online and the guests and stuff. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/ Share on other sites More sharing options...
mr_mind Posted December 2, 2007 Share Posted December 2, 2007 You are looking for php startsession(); you can find this in the php maual at php.net Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-403975 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 You are looking for php startsession(); you can find this in the php maual at php.net  startsession() doesn't exist, I think your thinking about session_start()...although I'm not sure how that relates to the question asked.  Just do a google for "PHP online users tutorial", tons of results come up for this topic. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-403978 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Theres only about 2 scripts, one using sessions which i dont want to use, and the other one would kill the database... i was just wondering if anyone has their own way of doing it.. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-403984 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 If you want to know how many users are online, this is what you need to do. Â Put a datetime field in the users table called "last_active" On your header page, put an update query that will update that field for that specific user to the current date/time. Â Now on your online users page, do a query like this SELECT username FROM users WHERE last_active > (NOW - INTERVAL 5 minute) Â That will get every user (registered) thats been active within the last 5 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404001 Share on other sites More sharing options...
Demont Posted December 2, 2007 Share Posted December 2, 2007 Not to jack this thread or anything, but would the query work like this as well? Â SELECT username FROM users WHERE last_active == (NOW) Â To show who is online at that moment, and not the last 5 minutes? Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404012 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 Not to jack this thread or anything, but would the query work like this as well? Â SELECT username FROM users WHERE last_active == (NOW) Â To show who is online at that moment, and not the last 5 minutes? Â You only use one equal sign in MySQL, other than that though, that would get anyone online at that EXACT moment which would be pretty pointless as it would be hard to catch people who were being active. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404016 Share on other sites More sharing options...
Demont Posted December 2, 2007 Share Posted December 2, 2007 I'm not exactly sure how to use the MySQL update query with date/time... Â the query is: Â mysql_query("UPDATE username SET last_active = '?' WHERE username = '$username'"); Â Is that somewhat right? the ? of course signifying, I don't know what to do... ??? Â Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404024 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 UPDATE users SET last_active=NOW() WHERE username = '$username' Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404026 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 I actually like that idea better then the way ive started doing it, it seems more logical and database friendly. I might write a tut on it after im done. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404030 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 mysql_query("UPDATE teams SET lastactive=NOW() WHERE id='{$_COOKIE['user']}'"); Â That gives no errors, but lastactive is still blank after updating. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404034 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 Change it to mysql_query("UPDATE teams SET lastactive=NOW() WHERE id='{$_COOKIE['user']}'")or die(mysql_error()); Â Â Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404037 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Still no errors..... i think imma come up with a better way for time.... Â $timestamp = time(); Then updating it with that...then it would be easier to work with later. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404039 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 Are you sure the DB field is a datetime? Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404041 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 //Last Active Update if(isset($_COOKIE['user'])){ $timestamp = time(); mysql_query("UPDATE teams SET lastactive='$timestamp' WHERE id='{$_COOKIE['user']}'") or die(mysql_error()); } Â Is the code The lastactive field is int(15) Â Doesnt wanna update for some reason... no errors either....weird. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404042 Share on other sites More sharing options...
pocobueno1388 Posted December 2, 2007 Share Posted December 2, 2007 //Last Active Update if(isset($_COOKIE['user'])){ $timestamp = time(); mysql_query("UPDATE teams SET lastactive='$timestamp' WHERE id='{$_COOKIE['user']}'") or die(mysql_error()); } Â Is the code The lastactive field is int(15) Â Did that work for you? If not, change you field to a datetime. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404043 Share on other sites More sharing options...
Demont Posted December 2, 2007 Share Posted December 2, 2007 I was having the problem Zepo was having. Nothing showing up, and now for some reason, users can't log in, and it has me stumped. Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404044 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 It works now... i just have to do the other parts of the code...thanks. Â Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404045 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Ok, now how would i go on to tackle pulling from the database's users last updated within 300 second.... any ideas? I was thinking something like this, but idk how to use inequalities like that... $timestamp = time(); $timeout = $timestamp-$timeoutseconds; $uonline = mysql_num_rows(mysql_query("SELECT teamid FROM teamsonline WHERE lastupdated>$timeout")); Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404048 Share on other sites More sharing options...
Zepo. Posted December 2, 2007 Author Share Posted December 2, 2007 Forgot in the last code chunk $timeoutseconds ="300"; Quote Link to comment https://forums.phpfreaks.com/topic/79771-users-online-script/#findComment-404061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.