Shaun13 Posted May 15, 2007 Share Posted May 15, 2007 Hi, I am creating a forum and I was wondering how I could create a users online legend at the bottom of the index. I tried something like echo "$myusername" and it will only display your username. How could I accomplish this? ~Shaun Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/ Share on other sites More sharing options...
john010117 Posted May 15, 2007 Share Posted May 15, 2007 Since I don't know the structure of your forum, I can't quite say. But the basic idea would be to have a column in your users and/or sessions table named $logged_in, and the only values would be 1 for true and 0 for false. Then, run a mysql_query on the table WHERE logged_in = 1. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253216 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 If they like closed the window, how would it log them out? Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253218 Share on other sites More sharing options...
john010117 Posted May 15, 2007 Share Posted May 15, 2007 Let's say you wanted to log a user out after 10 minutes. Create a new function named whatever you want, and a new column in the table named something like last_activity and set the type to timestamp. In the function, use strtotime to check when the user was last active, and if that was more than 10 minutes ago, unset the session for that user. Put the function in a file, and include/require that for every secure page. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253221 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 Could you create the function for me? I don't know how. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253224 Share on other sites More sharing options...
Psycho Posted May 15, 2007 Share Posted May 15, 2007 Could you create the function for me? I don't know how. Since we do not know the structure of your database, no. Are you using a CMS or is this your own build? Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253228 Share on other sites More sharing options...
john010117 Posted May 15, 2007 Share Posted May 15, 2007 http://us2.php.net/manual/en/function.create-function.php Look at example 722. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253229 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 So what am i putting for the options for the new last_activity field? Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253231 Share on other sites More sharing options...
john010117 Posted May 15, 2007 Share Posted May 15, 2007 Set the Type to TIMESTAMP, and Attributes to ON UPDATE CURRENT_TIMESTAMP. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253232 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 Ok, I have the new field, now what? ~Shaun Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253925 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 Can anyone help? ??? ~Shaun Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-253956 Share on other sites More sharing options...
Shaun13 Posted May 15, 2007 Author Share Posted May 15, 2007 I would really appreciate some help. ~Shaun Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-254039 Share on other sites More sharing options...
Shaun13 Posted May 16, 2007 Author Share Posted May 16, 2007 John, help please? Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-254080 Share on other sites More sharing options...
john010117 Posted May 16, 2007 Share Posted May 16, 2007 First of all, list all the fields you have for the table (as well as their types). I need to know what you're table structure is first. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-254171 Share on other sites More sharing options...
radar Posted May 16, 2007 Share Posted May 16, 2007 http://www.phpfreaks.com/forums/index.php/topic,140745.0.html ive copied some code into this thread that is just what you are looking for... it's the 2nd one in my post. Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-254250 Share on other sites More sharing options...
AbydosGater Posted May 16, 2007 Share Posted May 16, 2007 You should also check out this tutorial on phpIT. I was the same as you just a few months back didnt have a clue. You might not be able to use this exact code from the tutorial but it will give you great insight to how such functions should work. Tutorial Here. Hope its helpful. Andy Link to comment https://forums.phpfreaks.com/topic/51417-users-online-type-thing/#findComment-254284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.