Jump to content

Uers's online


phrozenfire

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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?

Thanks

Dane
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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 as

if 'valid_user' = logged in

UPDATE 'last_viewed' TIME

Am i along the right tracks?

Thanks
Link to comment
Share on other sites

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
Link to comment
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.