SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sending time counter to next page

    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.

    How would you do this? Is it possible to send in javascript value to the next page? Otherwise I have some other ideas, but I am not sure which is the most common:
    1.
    On page leave (if this exists in javascript?) call with ajax timer.php where you assign time to the session.
    2.
    On each 5 seconds call with ajax timer.php where you assign time to the session.
    3.
    Do sql call for each 5 seconds. I guess this is not ok because it is too wasting.

    4.
    Any other solution?

    Thank you

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    Internet
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. So probably I can not pass some kind of javascript session to the next page, it should be done on server side?

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could use javascript and cookies but I would prefer to keep track of the time server side.

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2009
    Location
    Internet
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meee View Post
    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?
    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.

  7. #7
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by meee View Post
    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?
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •