Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/133109-whos-online-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692222
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692519
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/133109-whos-online-help/#findComment-692521
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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