Jump to content

Determining if server time was midnight?


Smudly

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/
Share on other sites

I don't see how that helps you.  What makes more sense is to store the current Date.  Your clientside ajax or whatever, can periodically check this at the server.  If on any poll, the startDate != the serverDate, then you do your reset.  Needless to say the date changes at midnight, but when you think about it, midnight is simply an indication that you're in a new day.

Alright, ya I'm not sure if Cron is what I'm after. Here is a bit of code that another person helped me setup. What do you guys think? Could this work?

 

if (!isset($_SESSION["date"]) || $_SESSION["date"] != date("Ymd")) {
        $_SESSION["date"] = date("Ymd");
        $_SESSION["bonus"] = 0;
} else {
        $_SESSION["bonus"]++;
}

echo "Counter = ", $_SESSION["bonus"];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.