Jump to content

how to show all current sessions?...


rootKID

Recommended Posts

hello w3schools once again.. was thinking..im building this new website with user-login's to the website.. is it possible to make a box that will show ALL logged in users within like 10 min or so?.. was just thinking about it...if yes, wonna give a clue about it?.. -thanks alot! :)...

Link to comment
Share on other sites

If you've written your login code correct, you should have a sessions table; just add a column to show when the user was last active. If you haven't got a sessions table, you are not of a level of PHP where you should be writing a login system. They're one of the trickiest things to write, and if you mess them up and get hacked, you will annoy a lot of people.

Link to comment
Share on other sites

first off, i know PHP...im educated in it... i also have wrote login systems before.. but the thing with the showing people who is logged in is a little new to me...and yes, i understand that many people will get pissed if i mess it up hehe :)... but fact to point, thanks.. will test the table idea later, i allready had it in my mind... just needed to think on how to proceed with it...but thanks anyways :)...

Link to comment
Share on other sites

You need to set up table to store session data. you need to use session_set_save_handler() or sessionHandlerInterface to override default session handling. by default sessions are stored in files and they don't associate with any user id or time. you need to set up both refference to user id and timestamp so that you can get the logged in user list of certain time span.

Link to comment
Share on other sites

ok.. will look into it, thanks :)...

Link to comment
Share on other sites

Don't worry, my applications don't use a sessions table in the database to keep track of current sessions, they normally use the default session handlers and correlate information in other database tables (like the users table). Hopefully that means that I'm actually at an experience level of PHP where I can write a login system. My salary and the number of people using our applications would seem to support that. Anyway, there's a set of custom session handling functions in this thread specifically to do what you want, they will remap PHP's session handling to store all sessions in a database instead of the default temp files, and it includes a function to look up the number of users active within a certain amount of time: http://w3schools.inv...?showtopic=9731 That code is over 6 years old, it uses the mysql extension instead of mysqli, but you should be able to get the general idea about what it does and use mysqli if you want to rewrite some of it. You could also convert it to a class instead of using the global variables and constants, which would also be better practice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...