I've looked everywhere, and google won't help me. =/ The scripts are either too complicated (and thus too hard on the server, I need something basic) or part of this huge thing I'd have to dissect.
All I want is when people log in to my game, for it to tick them as signed on. 15 minutes of inactivity, they're logged off. I was previously using IPB forums, but I've sinced just opted to code my own forums, and now I don't have a way to check this.
I was thinking I'd have it set "15" when they log in, and then every minute, it takes 1 away from all users with > 0 minutes logged in, and when it reaches 0, it doesn't consider them logged in anymore. This means, however, every page I'd have to set (maybe in the footer) the counter = 15 with mySQL. A whole query a page is something I don't want to do, along with a big query every one minute.
What should I do?
"members online" script.
Moderator: General Moderators
-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
Re: "members online" script.
Make a log in the database when the "User" logs on.
Edit: Born is a poor example, last modified, or updated would be much suffice.
Code: Select all
SELECT count(id) FROM `logins` WHERE `born` >= DATE_SUB(born, INTERVAL 15 MINUTE);
Last edited by Zoxive on Tue Feb 26, 2008 1:20 pm, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: "members online" script.
On every page, update the users last action time
Then basically do the exact same query as Zoxive to check for users that are currently online. Alternatively you can use ajax to poll the user every x seconds to determine if their browser is still open.
Code: Select all
UPDATE users SET lastonline = NOW() WHERE id = $userid-
Mightywayne
- Forum Contributor
- Posts: 237
- Joined: Sat Dec 09, 2006 6:46 am
Re: "members online" script.
Lol I'm not pro enough for AJAX yet, but thanks folks, that is a better way to do it.