Determining if server time was midnight?

Discussion in 'PHP' started by tanyania, Jul 21, 2011.

  1. #1
    I've got a variable that will increment upon a user's action. Example: They click a link, and it adds 1 to the variable. The variable is then shown to the screen. I want this variable to be reset to 0 for the user, anytime the server's time has hit Midnight.

    Could you provide a simple example script that does something like this so I can examine it and learn how it works please?
     
    tanyania, Jul 21, 2011 IP
  2. bogi

    bogi Well-Known Member

    Messages:
    482
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    140
    #2
    2 simple solutions:

    1, Cron job
    2, If you have enough traffic and/or you don't care if it resets some minutes later, you can check the time in a config file that is loaded every time a user visits a page on your site. You should also have another record in your (let's say options) table storing your last time of reset - either a timestamp or just the name/number of the day.

    Do you need a script to reset the variable for the user? "UPDATE `table` SET `var` = 0 WHERE `user` = 'youruser' :)
     
    bogi, Jul 21, 2011 IP
  3. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #3
    1. add a field contain date
    2. "UPDATE table SET click = 0 WHERE last_click < '" . date("Y-m-d") . "'"
    3. update clicks
    "UPDATE table SET click = click + 1, last_click = '" . date("Y-m-d") . "' WHERE user = 'youruser'"
     
    suryawl, Jul 22, 2011 IP