If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Session help

Hello!
I'm coding a forum, and I want users to receive a virtual coin for every minute they're online. I got the session up and working. So far there's a forum where users are able to post and reply threads.
About the coin system, my first problem is that I want to avoid users to abuse the system, so I want a 30 minutes timeout for the session.
Secondly, how do I determine how long the session has been active in PHP?
Thank you!

About the coin system, my first problem is that I want to avoid users to abuse the system, so I want a 30 minutes timeout for the session.

There isn't really a 'good' way to achieve that. PHP handles sessions differently on different systems. On some systems it will automatically close the session after 24 minutes (might be 22 actually..I can never remember the exact details ). The only thing you could do is to have a cron run every minute and scan each session file to see when it was opened but thats rather advanced and depends on all sorts of operating system permissions etc.

Originally Posted by KimLefevre

Secondly, how do I determine how long the session has been active in PHP?
Thank you!

Thats the easy part. Simply record the login time in the session:
$_SESSION['login_time'] = time();

Then you know how long ago they logged in.

The downside is you still don't really know when they've stopped viewing the site because PHP is reactive. The only thing you could really do is to see if there is more than 30 minutes since their last usage and if there is don't award any coins. If it's less than 30 minutes then award coins but again you're still up against the php automatic termination of sessions problem so I would suggest going for a 5 or 10 minute time instead