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?
Determining if server time was midnight?
Moderator: General Moderators
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
Re: Determining if server time was midnight?
Easiest way for this is to set up a cron job.
Re: Determining if server time was midnight?
cron is the easiest? Maybe. Depends how, where, and when the counter thing gets used.
It keeps track of the current date as YYYYMMDD: if that changes (or isn't around to begin with) the counter is set to zero. Exactly where the date and counter are stored doesn't matter.
Code: Select all
<?php
session_start();
if (!isset($_SESSION["date"]) || $_SESSION["date"] != date("Ymd")) {
$_SESSION["date"] = date("Ymd");
$_SESSION["counter"] = 0;
} else {
$_SESSION["counter"]++;
}
echo "Counter=", $_SESSION["counter"];-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
Re: Determining if server time was midnight?
Not sure if I understand your code well tasairis, but doesn't your code only get executed when a user interacts with the server?