Krazy1151 Posted November 17, 2008 Share Posted November 17, 2008 Hey guys! I am trying to code an who's online page. but..I don't want it as "there is one website viewing your website" I want it to be a page that has a table that goes like this.. A column would be for the players name and ID [NAME][#ID] .. basically just a table with the players that are online! instead of it saying "there is 1 player viewing your website" understand what I mean? Quote Link to comment https://forums.phpfreaks.com/topic/133109-whos-online-help/ Share on other sites More sharing options...
premiso Posted November 17, 2008 Share Posted November 17, 2008 Do you have any code started? The table I would/do use is: create TABLE user_session ( sessionhash varchar50 NOT NULL, userid int(11) NOT NULL, last_activity int(11) NOT NULL, primary key(sessionhash) ) You can do this with or without the sessionhash part, if you remove the session hash I would suggest putting the userid as the primary key. Then each page load you just query and pull out all users where last_activity < 5 minutes ago (or however many minutes you want). Hope that helps, if you are still confused, google "Who's Online PHP" and you should find many pre-made scripts. Quote Link to comment https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692222 Share on other sites More sharing options...
bogeyman Posted November 18, 2008 Share Posted November 18, 2008 You can use a table to store the session. To check who is online, just use SELECT statement to retrieve the data. In your PHP script, you also need to use the function session_set_save_handler() to override the default way of PHP in handling session. This article might be helpfull. I read this when I learn about storing session in database. shiflett.org/articles/storing-sessions-in-a-database Quote Link to comment https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692519 Share on other sites More sharing options...
JasonLewis Posted November 18, 2008 Share Posted November 18, 2008 Why not just an online and timeout column to the current users table. When the users signs in, set online to 1 and timeout to the current unix time. When they sign out, set it to 0. Then every time they change page check to see that timeout isn't less than the current time minus a certain amount of time (like 20 minutes). If it is less than, update online to 0 and log them out, if it isn't, update the timeout column to the current time. Then for your online list, just select all from users where online is equal to 1. Quote Link to comment https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692521 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.