Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-12-2012, 05:05 PM   PM User | #1
KimLefevre
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
KimLefevre is an unknown quantity at this point
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!
KimLefevre is offline   Reply With Quote
Old 12-12-2012, 10:28 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,496
Thanks: 44
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by KimLefevre View Post
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.

Quote:
Originally Posted by KimLefevre View Post
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
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:14 AM.


Advertisement
Log in to turn off these ads.