meee — 2010-12-20T14:58:10-05:00 — #1
I have a situation where I don't know how to search for solution, please help me:
User gets for every minute staying on the site 1 credit. Credit is updated each minute, even if the page is not reloaded. But also if the page is reloaded or user continue browsing to other pages inside our site, counter should continue where it stayed in the previous page. If the user leaves the site it doesn't need to continue.
On each 5 seconds call with ajax timer.php where you assign time to the session.
Do sql call for each 5 seconds. I guess this is not ok because it is too wasting.
Any other solution?
tribal_01 — 2010-12-20T15:41:58-05:00 — #2
I personally would use number 2. Maybe you can do it for 10 seconds instead?
You would have to impliment some sort of system where you make sure a user has actually be active, otherwise if a user left his/her browser open all night, each request to timer.php would keep the session alive and the user would rack up a LOAD of points. Maybe set an auto-timeout after X number of minutes? then use a captcha on the login page to attempt to prevent auto re-logins?
meee — 2010-12-20T15:46:04-05:00 — #3
system — 2010-12-20T15:56:01-05:00 — #4
meee — 2010-12-20T16:27:35-05:00 — #5
Of course, cookies :). Kalon why would you prefer server side? Cookies will give me even more accure data because I can store it every 2 seconds. If I would make ajax call for every 2 seconds, this could be quite wasting, but storing data each 2 seconds in cookies it won't make any bad for server. This is how I think, am I right?
tribal_01 — 2010-12-20T16:30:13-05:00 — #6
But you will still have to poll the server to update the time.
Why not store the login time of the user, then each request to timer.php just works out current_time - logged_in_time. This way no cookies are needed and and user wouldn't be able to modify the time as it does not get transferred over http.
system — 2010-12-20T16:46:44-05:00 — #7
I normally steer away from using cookies unless I must use them because I would have to come up with a Plan B for visitors who have cookies disabled in their browsers.