Please Help - Need to know if its possible to make a countUP counter

Discussion in 'PHP' started by Josiah123, Apr 13, 2010.

  1. #1
    Hello,

    I am trying to complete a project and my client has requested the following thing be created:

    A counter that starts at a specific number "X"
    The number goes up by a specific number each second "Y"
    When someone visits a site, the browser gets the number to start from on the server "X"
    and then they can visually see the number going up each second by "Y"
    When they close the browser, the number is still being counted up (this is being done server side)
    When they come back to the site, they see the correct number regarding the amount of time that has passed (if they come back 2 days later, they will see the number increased by 2 days of time)

    I know that this has to be done server side and the browser has to reference the number generated by the script on the server, but I need to know:

    1. If this is possible
    2. The general idea of how this is done?

    My design team is telling me that this is not possible to do but I'm almost certain it is, being that there are sites like this: http://www.usdebtclock.org/ on the web.

    Any insight by a knowledgeable person in this regard will be greatly appreciated.

    Thank you.
     
    Josiah123, Apr 13, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Your main problem is identifying the visitor on their return.

    If they are logged into the site you just have to save the time they were allocated their "X" and then on each return you output the updated value of "X". Javascript handles the visual "count up" but PHP generates the start value.

    If they aren't logged in you have bigger problems as you have to somehow identify Probably the best way would be to store a cookie with the date they are allocated "X" and then reference that cookie on subsequent visits.

    Sounds more like homework than a client project though :)
     
    sarahk, Apr 13, 2010 IP
  3. Josiah123

    Josiah123 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah the X and Y's do make it sound like a homework assignment, haha.

    Every user needs to see the same number at the same time, that information may be helpful. With this being the case, is it still needed to keep track of who visited the site using cookies? (there will be no login)
     
    Josiah123, Apr 13, 2010 IP
  4. mike30

    mike30 Well-Known Member

    Messages:
    887
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    140
    #4
    It is not real time value for everyone at the same time on the site you said. I checked it with two different browsers and they are not the same values. That said, the increased value of counters are on each client browser.

    I guess what we could do here is when the browser exits, we may store the greater value on database. Could it be what you mean?
     
    mike30, Apr 13, 2010 IP
  5. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Set the cookie to user and save the ip to database, You should create temporary table.
     
    guardian999, Apr 14, 2010 IP
  6. Josiah123

    Josiah123 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry if this was misleading...

    In short .. what would the process be to have a counter... that is always counting up from the time it is initiated. This would need to be something that would pull from a script that is run on the server. Therefore it is always running and thus when any user visits the site, they will never see the same number, it will always be higher than before etc etc.. From what I have gathered so far, this is something that would need to be executed with some cron jobs on the server.

    What I am trying to find out is if there is anything already out here on this vast world we call the internet, that would serve as a guide to implement this?

    Thanks!
     
    Josiah123, Apr 14, 2010 IP
  7. Warll

    Warll Peon

    Messages:
    122
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Josiah:
    include 'really_easy_functions.php'
    PHP:
    Seriously though does the number start again for each new user or is it for the entire site? This isn;t the kind of thing you would use cron for, all you need to save is one little static number and then run javascript based off of that.
     
    Warll, Apr 14, 2010 IP
  8. Josiah123

    Josiah123 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It is the same number for the entire site. The number does not start again for each new user.

    *Edit: The issue I was having is when they first created the counter, it would only count up while the user had the browser open, and would start at the same base number each time someone went to the site for the first time (this being because the counter was created 100% client side). What the client needs is one number that is always going up and for users to be able to see what the number is currently at, as well as see it counting up in real time on their browsers. The same number for every user.

    Thank you for all of the replys and help so far, and for all future help and replys.
     
    Josiah123, Apr 14, 2010 IP
  9. guardian999

    guardian999 Well-Known Member

    Messages:
    376
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #9
    guardian999, Apr 14, 2010 IP