phrozenfire Posted January 23, 2007 Share Posted January 23, 2007 Hi I basically just need to be able to display all logged in users.The actual log in authentication I'm able to cope with and I can also get logged in users into a dbase table so as to display them. However I'm stuck on how to delete them from the table in the event of them logging off the site. I found tutorials but as always seems to be the case they're never exactly what you need. In short how can I clean up a mySQL table if the user logs off and the session ends. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 23, 2007 Share Posted January 23, 2007 What I did was put a row in the users table named something like "last_clicked" and on every page the user clicked on it updated to the current time. Then on the online users page I checked if the last_clicked was within 2 minutes...and if it was it displayed there name on the list. I think that is the easiest way of going about it. Quote Link to comment Share on other sites More sharing options...
phrozenfire Posted January 23, 2007 Author Share Posted January 23, 2007 Oh ok thanks Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 23, 2007 Share Posted January 23, 2007 i would add a column to my table. call it 'logged_in'. within your login script, after you validate the user's username and password, add a sql query and UPDATE the column 'logged_in' in the row that matches the user's name and password. set the value for the 'logged_in' column to 1, if the user is logged in.when they log-out, add a sql query to UPDATE this field, and set it to 0.when you want to display all the users logged in... just query your database WHERE 'logged_in' = 1...simple as that. Quote Link to comment Share on other sites More sharing options...
phrozenfire Posted January 23, 2007 Author Share Posted January 23, 2007 Thanks to both of you Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 23, 2007 Share Posted January 23, 2007 [quote author=phrozenfire link=topic=123714.msg511804#msg511804 date=1169590341]Thanks to both of you[/quote]fo shizzle. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 23, 2007 Share Posted January 23, 2007 [quote author=boo_lolly link=topic=123714.msg511779#msg511779 date=1169588016]i would add a column to my table. call it 'logged_in'. within your login script, after you validate the user's username and password, add a sql query and UPDATE the column 'logged_in' in the row that matches the user's name and password. set the value for the 'logged_in' column to 1, if the user is logged in.when they log-out, add a sql query to UPDATE this field, and set it to 0.when you want to display all the users logged in... just query your database WHERE 'logged_in' = 1...simple as that.[/quote]I just thought of something, maybe silly but its worth asking.....What if the user does not log out and just closes the browser? Im guessing that to UPDATE the database to set logged_in to '0' the logout script must be ran?ThanksDane Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2007 Share Posted January 23, 2007 I would store the time they last viewed a page. On every page, update the field to the current time. Then calculate who's been on a page in the past X minutes. Even if they just close the page, it will stay more accurate. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted January 24, 2007 Share Posted January 24, 2007 [quote author=jesirose link=topic=123714.msg511867#msg511867 date=1169595143]I would store the time they last viewed a page. On every page, update the field to the current time. Then calculate who's been on a page in the past X minutes. Even if they just close the page, it will stay more accurate.[/quote]GOOD call. i should have thought of that. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 24, 2007 Share Posted January 24, 2007 So let me try and figure this out......Lets say for example you have created a session for 'valid_user'......... And on every page you, at the top of the page, include ("website_settings"); ...In that website settings file you have such thing asif 'valid_user' = logged inUPDATE 'last_viewed' TIMEAm i along the right tracks?Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 24, 2007 Share Posted January 24, 2007 Yes. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 24, 2007 Share Posted January 24, 2007 Ummm...I told you the exact same thing Jesirose told you on the first post. Maybe I am a bad explainer or something, hah. Quote Link to comment Share on other sites More sharing options...
gloveny Posted January 24, 2007 Share Posted January 24, 2007 Why dont you just use AJAX which updates a field in the database with a timestamp every 30 seconds. Anyone whos field is more than 30 seconds old is offline, and anyones whos field is lower than 30 seconds is on line...so the AJAX php SQL = Update users_table set onlinelast = now();This will happen every 30 seconds...then on the page where you want to display online users only, say this.... SELECT * from users_table where (now() - onlinelast < 30)heypresto Quote Link to comment 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.