I have a user system that I made, and I was wondering if anyone knew a PHP code that I could use to display all of the people logged into the MySQL database.

I have a user system that I made, and I was wondering if anyone knew a PHP code that I could use to display all of the people logged into the MySQL database.
you mean like a 'Who's Online' type thing?
+.net - omg it's coming o_o
On every login, use thetypa thing? I' poor at PHP, but it works on myne (yes I'm making a usersystem...) I'm assuming your connected to a table and a database... Right?PHP Code:<? if ($date_logged_online==('(date(D:M:Y - H:M-15))')-->%){
$database --> $array ==>
$rowselect['user_name_varible'];
$online_usr = $rowselect['user_nmae_varible'];
echo "'.$online_usr.' is ONLINE! <br>";
} else { echo "Your the only one online!"; ?>
It should work, Happy PHP! change "$rowselect" to the variable your using to get info from the database table.... It should show logged in people from the last 15 minutes, enjoy!
EDIT: $array is the editible variable to the variable ur connecting to table!
Last edited by D-Man22; 20-10-2008 at 04:37 PM.
In your users table, have a lastUpdated field.. on each page in the config.php (which should be called on most pages..) have a checkLogin() function which returns true/false.
updateUser can just update that field with time(), then just calculate everyone with a lastUpdated field in a period of say.. 15 minutes.PHP Code:if(checkLogin() == true) {
updateUser( $username );
}
That should calculate your "users online"
Sorry Don't Know about MySQL!![]()
Jordan
Exactly how I do it, thanks to you! I remember back in the day, when I used a boolean to represent on and off. Horrifically, illogical.In your users table, have a lastUpdated field.. on each page in the config.php (which should be called on most pages..) have a checkLogin() function which returns true/false.
updateUser can just update that field with time(), then just calculate everyone with a lastUpdated field in a period of say.. 15 minutes.PHP Code:if(checkLogin() == true) {
updateUser( $username );
}
That should calculate your "users online"
@OP: If you mean actual MySQL, as Fazon said use a user login/logout hook.
Btw, a hook is a script that is run on a specific event.
Use it to update a text file, as I'm guessing that would be the best way to retrieve it.
Then your whos online? code should just read off of that text file.
How could this hapen to meeeeeeeeeeeeeee?lol.
Why the hell write it to a text file? That's pretty illogical, and hooking it on the login/logout.. that's not going to make an accurate "who's online" if you don't update the last activity they did.. that's just going to make it on the login timestamp.Exactly how I do it, thanks to you! I remember back in the day, when I used a boolean to represent on and off. Horrifically, illogical.
@OP: If you mean actual MySQL, as Fazon said use a user login/logout hook.
Btw, a hook is a script that is run on a specific event.
Use it to update a text file, as I'm guessing that would be the best way to retrieve it.
Then your whos online? code should just read off of that text file.
Sounds pretty "illogical" to me.
The only "accurate" way todo it would be with the timestamp within a database, or make the sessions save to a directory (which can be set in php) then use some PHP code to count all sessions which have been active within a certain time, still uses timestamp but it grabs it from the php session files directly.
I have always done it with a timestamp in a user database, so my second thought could be completly useless.
Want to hide these adverts? Register an account for free!