Smudly Posted June 22, 2010 Share Posted June 22, 2010 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? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 22, 2010 Share Posted June 22, 2010 Are you storing the value in a database? Ken Quote Link to comment Share on other sites More sharing options...
Smudly Posted June 22, 2010 Author Share Posted June 22, 2010 No, I won't be storing either of the variables into a database. Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted June 22, 2010 Share Posted June 22, 2010 Make a cron job that runs a folder at midnight daily and just make it cleanup everyones increment? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 22, 2010 Share Posted June 22, 2010 If you're not storing the value in a database, how are you keeping track of the value between reloads of the page? Ken Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted June 22, 2010 Share Posted June 22, 2010 If you're not storing the value in a database, how are you keeping track of the value between reloads of the page? Ken Good question, I was thinking exactly the same thing, Maybe a file or a sql file? Quote Link to comment Share on other sites More sharing options...
Smudly Posted June 22, 2010 Author Share Posted June 22, 2010 I think i'm just going to go with a Cron Job. Going to research that. Thanks guys Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 22, 2010 Share Posted June 22, 2010 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. Quote Link to comment Share on other sites More sharing options...
Smudly Posted June 22, 2010 Author Share Posted June 22, 2010 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"]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.