Page 1 of 1

"members online" script.

Posted: Tue Feb 26, 2008 12:09 pm
by Mightywayne
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?

Re: "members online" script.

Posted: Tue Feb 26, 2008 12:38 pm
by Zoxive
Make a log in the database when the "User" logs on.

Code: Select all

SELECT count(id) FROM `logins` WHERE `born` >= DATE_SUB(born, INTERVAL 15 MINUTE);
Edit: Born is a poor example, last modified, or updated would be much suffice.

Re: "members online" script.

Posted: Tue Feb 26, 2008 1:11 pm
by John Cartwright
On every page, update the users last action time

Code: Select all

UPDATE users SET lastonline = NOW() WHERE id = $userid
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.

Re: "members online" script.

Posted: Tue Feb 26, 2008 2:00 pm
by Mightywayne
Lol I'm not pro enough for AJAX yet, but thanks folks, that is a better way to do it.