Edak Posted May 22, 2009 Share Posted May 22, 2009 Hey I would like to know the best way to allow a user to do something once every 24 hours. My thought was to make a table and store the date in that, but it's a reputation program and what if that user gave rep to 100 people that day, that's 100 tables filled just to hold info so he can't give any of those people rep again. I'd prefer you didn't actually code it out, just pointed me in the right direction. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/ Share on other sites More sharing options...
MasterACE14 Posted May 22, 2009 Share Posted May 22, 2009 store the time(); in your database of when they do whatever it is, and then if they try to do it again check against the time in the database to see if it is greater then 24 hours compared to the current time. Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839649 Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 - Have a field in your database for storing the last time they performed this action. - Every time they perform this action you need to do a check to see if the difference between the last time they committed this action and the current time, was > 24 hours. - If it is > 24 hours, let them perform the task and update the field with the current time. - If not, display your error message, and leave the time that was in the field. Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839651 Share on other sites More sharing options...
Ken2k7 Posted May 22, 2009 Share Posted May 22, 2009 Record the last time the user gave someone a rep in the database. Then use SQL to check if the user has given 100 rep points that day AND the time of the last rep given is less than 24 hours ago. Like what the other 2 people says, but also check for how many reps the user given that day if you want to allow 100 per day. Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839653 Share on other sites More sharing options...
BK87 Posted May 22, 2009 Share Posted May 22, 2009 I was about to write a response but then I said hmmm let me refresh this just in case and there it was 2 responses. So here is my response, the two posts above mine, are both excellent ideas =D Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839655 Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 I was about to write a response but then I said hmmm let me refresh this just in case and there it was 2 responses. So here is my response, the two posts above mine, are both excellent ideas =D The more the merrier! Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839656 Share on other sites More sharing options...
.josh Posted May 22, 2009 Share Posted May 22, 2009 I think the OP is wanting the user to be able to hand out rep all day long to people, but he can't click the same person again until 24hrs have passed. All you need is a single table. 3 columns: userId, friendId, timestamp. Every time a user clicks on a link, your script checks to see if a row exists matching the user and friend. And the timestamp is less than 24 hours. You would then have a cronjob setup to run a script every 24 hours to prune old entries. Quote Link to comment https://forums.phpfreaks.com/topic/159208-once-every-24-hours-in-php/#findComment-839706 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.