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? Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/ 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 Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075366 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. Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075401 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? Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075404 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 Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075408 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? Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075410 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 Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075411 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. Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075419 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"]; Link to comment https://forums.phpfreaks.com/topic/205501-determining-if-server-time-was-midnight/#findComment-1075422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.